Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat: add webpack4 support #495

Merged
merged 46 commits into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fd52211
refactor: get app directory from CLI
sis0k0 Mar 6, 2018
3591fc6
test: refactor to use NativeScriptCommonModule instead of
sis0k0 Mar 14, 2018
2e94056
fix: return right value from shouldSnapshot
sis0k0 Mar 15, 2018
4a04dbc
fix: get project data safely
sis0k0 Mar 19, 2018
376d820
refactor: get projectDir directly from projectData
sis0k0 Mar 19, 2018
4f7a93d
refactor: export APP_DIR constant from projectHelpers
sis0k0 Mar 19, 2018
916d8f9
fix: default value for args for safeGet function
sis0k0 Mar 19, 2018
db588f3
fix(prepare): clean platforms/.../app/ when running webpack
sis0k0 Mar 17, 2018
7eccdab
fix-next: copy only the target platform App Resources
sis0k0 Mar 17, 2018
727c789
fix: remove NsNodeGlobalsPlugin as it's not needed anymore
sis0k0 Mar 17, 2018
fee4be7
chore: bump versions of deps to all supporting webpack 4
sis0k0 Mar 21, 2018
bd4ce6f
refactor: remove vendor chunk from templates
sis0k0 Mar 21, 2018
1819f28
fix: upgrade nativescript target to webpack 4
sis0k0 Mar 18, 2018
0f6ad11
fix: fix common chunk for angular
sis0k0 Mar 22, 2018
50604e3
refactor: remove obsolete loaders
sis0k0 Mar 22, 2018
c0d1867
wip
sis0k0 Mar 22, 2018
8d99b38
chore: bump webpack version to 4.3
sis0k0 Mar 28, 2018
d7ef95b
feat: add loader for registering android app components
sis0k0 Mar 28, 2018
9ccf5d9
chore: update package dependencies
sis0k0 Mar 28, 2018
c86df12
feat: update snapshot plugin for webpack 4
sis0k0 Mar 28, 2018
46782c4
refactor: update webpack config templates
sis0k0 Mar 28, 2018
fc3a940
refactor: remove old update scripts (#475)
sis0k0 Mar 28, 2018
ed04170
refactor(demo): remove vendor-platform from gitignore
sis0k0 Mar 29, 2018
0efee0c
fix(templates): split chunks for js
sis0k0 Mar 29, 2018
a3606c8
fix(templates/ts): use .ts for entries in android app components loader
sis0k0 Mar 29, 2018
efec44a
fix: unshift instead of push the android-app-components-loader
sis0k0 Mar 29, 2018
7aa0aee
fix(templates/webpack.angular): test against correct entry path for
sis0k0 Mar 29, 2018
27e0a95
chore: update JavaScript demo dependencies
sis0k0 Mar 29, 2018
94a09e9
chore: update TypeScript demo dependencies
sis0k0 Mar 29, 2018
494aad6
chore: update Angular demo dependencies
sis0k0 Mar 29, 2018
c87caab
fix(deps): add missing @angular-devkit/core dependency for @ngtools/w…
manoldonev Mar 29, 2018
5829156
refactor: update webpack config templates
manoldonev Apr 3, 2018
3d6d160
fix: restore regular Node.js __dirname behavior
manoldonev Apr 4, 2018
cb24936
chore: bump ngtools/webpack and angular-devkit/core versions to latest
sis0k0 Apr 5, 2018
ae60720
fix(PlatformFSPlugin): use Map instead of object for timestamps
sis0k0 Apr 5, 2018
3b885c7
chore: bump deps versions
sis0k0 Apr 11, 2018
1dd2000
fix-next: get properly project data from {N} CLI
sis0k0 Apr 6, 2018
aae7a16
Merge branch 'master' into sis0k0/webpack4
manoldonev Apr 17, 2018
39c8742
fix: disable pathinfo to speedup build
sis0k0 Apr 17, 2018
546e11c
chore(deps): update demo apps' dependencies
manoldonev Apr 18, 2018
9673a86
Merge branch 'master' into sis0k0/webpack4
manoldonev Apr 18, 2018
782c241
chore(deps): update demo apps' dependencies
manoldonev Apr 18, 2018
7fe2599
Merge branch 'master' into sis0k0/webpack4
manoldonev Apr 18, 2018
776eede
Merge branch 'master' into sis0k0/webpack4
manoldonev Apr 23, 2018
c0eb96c
fix: android app components loader on Windows
manoldonev Apr 23, 2018
0f77ce5
Merge branch 'master' into sis0k0/webpack4
sis0k0 Apr 25, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions android-app-components-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = function(source) {
this.cacheable();
const { modules } = this.query;
const imports = modules.map(m => `require("${m}");`).join("\n");
const augmentedSource = `
if (!global["__snapshot"]) {
${imports}
}

${source}
`;

this.callback(null, augmentedSource);
};
5 changes: 0 additions & 5 deletions demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ test-results.xml
tsconfig.aot.json

vendor.js
vendor-platform.android.js
vendor-platform.ios.js

vendor.ts
vendor-platform.android.ts
vendor-platform.ios.ts

webpack.config.js
41 changes: 22 additions & 19 deletions demo/AngularApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
}
},
"dependencies": {
"@angular/common": "~5.2.0",
"@angular/compiler": "~5.2.0",
"@angular/core": "~5.2.0",
"@angular/forms": "~5.2.0",
"@angular/http": "~5.2.0",
"@angular/platform-browser": "~5.2.0",
"@angular/platform-browser-dynamic": "~5.2.0",
"@angular/router": "~5.2.0",
"nativescript-angular": "next",
"@angular/common": "~6.0.0-rc.0",
"@angular/compiler": "~6.0.0-rc.0",
"@angular/core": "~6.0.0-rc.0",
"@angular/forms": "~6.0.0-rc.0",
"@angular/http": "~6.0.0-rc.0",
"@angular/platform-browser": "~6.0.0-rc.0",
"@angular/platform-browser-dynamic": "~6.0.0-rc.0",
"@angular/router": "~6.0.0-rc.0",
"nativescript-angular": "rc",
"nativescript-theme-core": "~1.0.2",
"reflect-metadata": "~0.1.8",
"rxjs": "^5.5.0",
"rxjs": "~6.0.0-beta.1",
"tns-core-modules": "next",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "~5.2.0",
"@ngtools/webpack": "~1.9.4",
"@angular-devkit/core": "~0.5.5",
"@angular/compiler-cli": "~6.0.0-rc.0",
"@ngtools/webpack": "~6.0.0-rc.3",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
Expand All @@ -39,7 +40,8 @@
"babylon": "6.18.0",
"chai": "~4.1.1",
"chai-as-promised": "~7.1.1",
"copy-webpack-plugin": "~4.3.0",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
Expand All @@ -51,14 +53,15 @@
"nativescript-dev-typescript": "next",
"nativescript-dev-webpack": "file:../..",
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.2.1",
"sass-loader": "^6.0.6",
"typescript": "~2.6.2",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"typescript": "~2.7.2",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
18 changes: 12 additions & 6 deletions demo/JavaScriptApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
"tns-core-modules": "next"
},
"devDependencies": {
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"copy-webpack-plugin": "~4.0.1",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
Expand All @@ -33,11 +37,13 @@
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"sass-loader": "^6.0.6",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
20 changes: 11 additions & 9 deletions demo/TypeScriptApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
"tns-core-modules": "next"
},
"devDependencies": {
"awesome-typescript-loader": "~3.1.3",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
"awesome-typescript-loader": "~5.0.0-1",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"copy-webpack-plugin": "~4.0.1",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.5.1",
"css-loader": "~0.28.7",
"extract-text-webpack-plugin": "~3.0.0",
"extract-text-webpack-plugin": "~3.0.2",
"lazy": "1.0.11",
"mocha": "~3.5.0",
"mocha-junit-reporter": "^1.13.0",
Expand All @@ -36,14 +37,15 @@
"nativescript-dev-typescript": "next",
"nativescript-dev-webpack": "file:../..",
"nativescript-worker-loader": "~0.8.1",
"node-sass": "^4.7.2",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
"sass-loader": "^6.0.6",
"typescript": "~2.6.2",
"webpack": "~3.10.0",
"resolve-url-loader": "~2.3.0",
"sass-loader": "~6.0.6",
"typescript": "~2.7.2",
"uglifyjs-webpack-plugin": "~1.2.4",
"webpack": "~4.5.0",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "^1.1.0"
"webpack-cli": "~2.0.14",
"webpack-sources": "~1.1.0"
},
"scripts": {
"ns-bundle": "ns-bundle",
Expand Down
14 changes: 8 additions & 6 deletions dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,28 @@ function addDependency(deps, name, version, force) {

function getRequiredDeps(packageJson) {
const deps = {
"webpack": "~3.10.0",
"webpack": "~4.5.0",
"webpack-cli": "~2.0.14",
"webpack-bundle-analyzer": "^2.9.1",
"webpack-sources": "~1.1.0",
"clean-webpack-plugin": "~0.1.19",
"copy-webpack-plugin": "~4.3.0",
"copy-webpack-plugin": "~4.5.1",
"raw-loader": "~0.5.1",
"css-loader": "~0.28.7",
"nativescript-worker-loader": "~0.8.1",
"resolve-url-loader": "~2.2.1",
"resolve-url-loader": "~2.3.0",
"extract-text-webpack-plugin": "~3.0.2",
"uglifyjs-webpack-plugin": "~1.1.6",
"uglifyjs-webpack-plugin": "~1.2.4",
};

if (isAngular({packageJson})) {
Object.assign(deps, {
"@angular/compiler-cli": packageJson.dependencies["@angular/core"],
"@ngtools/webpack": "~1.9.4",
"@ngtools/webpack": "~6.0.0-rc.3",
"@angular-devkit/core": "~0.5.5",
});
} else if (isTypeScript({packageJson})) {
Object.assign(deps, { "awesome-typescript-loader": "~3.1.3" });
Object.assign(deps, { "awesome-typescript-loader": "~5.0.0" });
}

if (isSass({packageJson})) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function buildEnvData($projectData, platform, env) {
const appResourcesPath = getAppResourcesPathFromProjectData($projectData);
Object.assign(envData,
appPath && { appPath },
appResourcesPath && { appResourcesPath }
appResourcesPath && { appResourcesPath },
);

return envData;
Expand Down
68 changes: 41 additions & 27 deletions nativescript-target/NsJsonpChunkTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var ConcatSource = require("webpack-sources").ConcatSource;
var Template = require("webpack/lib/Template");
"use strict";

function JsonpChunkTemplatePlugin() { }
module.exports = JsonpChunkTemplatePlugin;

JsonpChunkTemplatePlugin.prototype.apply = function (chunkTemplate) {
const ConcatSource = require("webpack-sources").ConcatSource;

//JSONP version
chunkTemplate.plugin("render", function (modules, chunk) {
var jsonpFunction = this.outputOptions.jsonpFunction;
var source = new ConcatSource();
source.add(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ",");
source.add(modules);
var entries = [chunk.entryModule].filter(Boolean).map(function (m) {
return m.id;
class JsonpChunkTemplatePlugin {
apply(chunkTemplate) {
chunkTemplate.hooks.render.tap(
"JsonpChunkTemplatePlugin",
(modules, chunk) => {
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
const globalObject = chunkTemplate.outputOptions.globalObject;
const source = new ConcatSource();
source.add(
`(${globalObject}[${JSON.stringify(jsonpFunction)}] = ${
globalObject
}[${JSON.stringify(jsonpFunction)}] || []).push([${JSON.stringify(
chunk.ids
)},`
);
source.add(modules);
const entries = [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
if (entries.length > 0) {
source.add(`,${JSON.stringify(entries)}`);
}
source.add("])");
return source;
}
);
chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => {
hash.update("JsonpChunkTemplatePlugin");
hash.update("4");
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
});
if (entries.length > 0) {
source.add("," + JSON.stringify(entries));
}
source.add(")");
return source;
});
chunkTemplate.plugin("hash", function (hash) {
hash.update("JsonpChunkTemplatePlugin");
hash.update("3");
hash.update(this.outputOptions.jsonpFunction + "");
hash.update(this.outputOptions.library + "");
});
};
}
}
module.exports = JsonpChunkTemplatePlugin;

27 changes: 0 additions & 27 deletions nativescript-target/NsJsonpHotUpdateChunkTemplatePlugin.js

This file was deleted.

Loading