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

Commit eefce39

Browse files
SvetoslavTsenovsis0k0
authored andcommitted
feat: add webpack4 support (#495)
1 parent 8fd544b commit eefce39

32 files changed

+697
-617
lines changed

Diff for: android-app-components-loader.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function(source) {
2+
this.cacheable();
3+
const { modules } = this.query;
4+
const imports = modules.map(m => `require("${m}");`).join("\n");
5+
const augmentedSource = `
6+
if (!global["__snapshot"]) {
7+
${imports}
8+
}
9+
10+
${source}
11+
`;
12+
13+
this.callback(null, augmentedSource);
14+
};

Diff for: demo/.gitignore

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ test-results.xml
1414
tsconfig.aot.json
1515

1616
vendor.js
17-
vendor-platform.android.js
18-
vendor-platform.ios.js
19-
2017
vendor.ts
21-
vendor-platform.android.ts
22-
vendor-platform.ios.ts
2318

2419
webpack.config.js

Diff for: demo/AngularApp/package.json

+22-19
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@
1313
}
1414
},
1515
"dependencies": {
16-
"@angular/common": "~5.2.0",
17-
"@angular/compiler": "~5.2.0",
18-
"@angular/core": "~5.2.0",
19-
"@angular/forms": "~5.2.0",
20-
"@angular/http": "~5.2.0",
21-
"@angular/platform-browser": "~5.2.0",
22-
"@angular/platform-browser-dynamic": "~5.2.0",
23-
"@angular/router": "~5.2.0",
24-
"nativescript-angular": "next",
16+
"@angular/common": "~6.0.0-rc.0",
17+
"@angular/compiler": "~6.0.0-rc.0",
18+
"@angular/core": "~6.0.0-rc.0",
19+
"@angular/forms": "~6.0.0-rc.0",
20+
"@angular/http": "~6.0.0-rc.0",
21+
"@angular/platform-browser": "~6.0.0-rc.0",
22+
"@angular/platform-browser-dynamic": "~6.0.0-rc.0",
23+
"@angular/router": "~6.0.0-rc.0",
24+
"nativescript-angular": "rc",
2525
"nativescript-theme-core": "~1.0.2",
2626
"reflect-metadata": "~0.1.8",
27-
"rxjs": "^5.5.0",
27+
"rxjs": "~6.0.0-beta.1",
2828
"tns-core-modules": "next",
2929
"zone.js": "^0.8.4"
3030
},
3131
"devDependencies": {
32-
"@angular/compiler-cli": "~5.2.0",
33-
"@ngtools/webpack": "~1.9.4",
32+
"@angular-devkit/core": "~0.5.5",
33+
"@angular/compiler-cli": "~6.0.0-rc.0",
34+
"@ngtools/webpack": "~6.0.0-rc.3",
3435
"@types/chai": "^4.0.2",
3536
"@types/mocha": "^2.2.41",
3637
"@types/node": "^7.0.5",
@@ -39,7 +40,8 @@
3940
"babylon": "6.18.0",
4041
"chai": "~4.1.1",
4142
"chai-as-promised": "~7.1.1",
42-
"copy-webpack-plugin": "~4.3.0",
43+
"clean-webpack-plugin": "~0.1.19",
44+
"copy-webpack-plugin": "~4.5.1",
4345
"css-loader": "~0.28.7",
4446
"extract-text-webpack-plugin": "~3.0.2",
4547
"lazy": "1.0.11",
@@ -51,14 +53,15 @@
5153
"nativescript-dev-typescript": "next",
5254
"nativescript-dev-webpack": "file:../..",
5355
"nativescript-worker-loader": "~0.8.1",
54-
"node-sass": "^4.7.1",
5556
"raw-loader": "~0.5.1",
56-
"resolve-url-loader": "~2.2.1",
57-
"sass-loader": "^6.0.6",
58-
"typescript": "~2.6.2",
59-
"webpack": "~3.10.0",
57+
"resolve-url-loader": "~2.3.0",
58+
"sass-loader": "~6.0.6",
59+
"typescript": "~2.7.2",
60+
"uglifyjs-webpack-plugin": "~1.2.4",
61+
"webpack": "~4.5.0",
6062
"webpack-bundle-analyzer": "^2.9.1",
61-
"webpack-sources": "^1.1.0"
63+
"webpack-cli": "~2.0.14",
64+
"webpack-sources": "~1.1.0"
6265
},
6366
"scripts": {
6467
"ns-bundle": "ns-bundle",

Diff for: demo/JavaScriptApp/package.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
"tns-core-modules": "next"
1818
},
1919
"devDependencies": {
20+
"@types/chai": "^4.0.2",
21+
"@types/mocha": "^2.2.41",
22+
"@types/node": "^7.0.5",
2023
"babel-traverse": "6.26.0",
2124
"babel-types": "6.26.0",
2225
"babylon": "6.18.0",
23-
"copy-webpack-plugin": "~4.0.1",
26+
"clean-webpack-plugin": "~0.1.19",
27+
"copy-webpack-plugin": "~4.5.1",
2428
"css-loader": "~0.28.7",
25-
"extract-text-webpack-plugin": "~3.0.0",
29+
"extract-text-webpack-plugin": "~3.0.2",
2630
"lazy": "1.0.11",
2731
"mocha": "~3.5.0",
2832
"mocha-junit-reporter": "^1.13.0",
@@ -33,11 +37,13 @@
3337
"nativescript-worker-loader": "~0.8.1",
3438
"node-sass": "^4.7.1",
3539
"raw-loader": "~0.5.1",
36-
"resolve-url-loader": "~2.1.0",
37-
"sass-loader": "^6.0.6",
38-
"webpack": "~3.10.0",
40+
"resolve-url-loader": "~2.3.0",
41+
"sass-loader": "~6.0.6",
42+
"uglifyjs-webpack-plugin": "~1.2.4",
43+
"webpack": "~4.5.0",
3944
"webpack-bundle-analyzer": "^2.9.1",
40-
"webpack-sources": "^1.1.0"
45+
"webpack-cli": "~2.0.14",
46+
"webpack-sources": "~1.1.0"
4147
},
4248
"scripts": {
4349
"ns-bundle": "ns-bundle",

Diff for: demo/TypeScriptApp/package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
"tns-core-modules": "next"
1818
},
1919
"devDependencies": {
20-
"awesome-typescript-loader": "~3.1.3",
2120
"@types/chai": "^4.0.2",
2221
"@types/mocha": "^2.2.41",
2322
"@types/node": "^7.0.5",
23+
"awesome-typescript-loader": "~5.0.0-1",
2424
"babel-traverse": "6.26.0",
2525
"babel-types": "6.26.0",
2626
"babylon": "6.18.0",
27-
"copy-webpack-plugin": "~4.0.1",
27+
"clean-webpack-plugin": "~0.1.19",
28+
"copy-webpack-plugin": "~4.5.1",
2829
"css-loader": "~0.28.7",
29-
"extract-text-webpack-plugin": "~3.0.0",
30+
"extract-text-webpack-plugin": "~3.0.2",
3031
"lazy": "1.0.11",
3132
"mocha": "~3.5.0",
3233
"mocha-junit-reporter": "^1.13.0",
@@ -36,14 +37,15 @@
3637
"nativescript-dev-typescript": "next",
3738
"nativescript-dev-webpack": "file:../..",
3839
"nativescript-worker-loader": "~0.8.1",
39-
"node-sass": "^4.7.2",
4040
"raw-loader": "~0.5.1",
41-
"resolve-url-loader": "~2.1.0",
42-
"sass-loader": "^6.0.6",
43-
"typescript": "~2.6.2",
44-
"webpack": "~3.10.0",
41+
"resolve-url-loader": "~2.3.0",
42+
"sass-loader": "~6.0.6",
43+
"typescript": "~2.7.2",
44+
"uglifyjs-webpack-plugin": "~1.2.4",
45+
"webpack": "~4.5.0",
4546
"webpack-bundle-analyzer": "^2.9.1",
46-
"webpack-sources": "^1.1.0"
47+
"webpack-cli": "~2.0.14",
48+
"webpack-sources": "~1.1.0"
4749
},
4850
"scripts": {
4951
"ns-bundle": "ns-bundle",

Diff for: dependencyManager.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,28 @@ function addDependency(deps, name, version, force) {
5858

5959
function getRequiredDeps(packageJson) {
6060
const deps = {
61-
"webpack": "~3.10.0",
61+
"webpack": "~4.5.0",
62+
"webpack-cli": "~2.0.14",
6263
"webpack-bundle-analyzer": "^2.9.1",
6364
"webpack-sources": "~1.1.0",
6465
"clean-webpack-plugin": "~0.1.19",
65-
"copy-webpack-plugin": "~4.3.0",
66+
"copy-webpack-plugin": "~4.5.1",
6667
"raw-loader": "~0.5.1",
6768
"css-loader": "~0.28.7",
6869
"nativescript-worker-loader": "~0.8.1",
69-
"resolve-url-loader": "~2.2.1",
70+
"resolve-url-loader": "~2.3.0",
7071
"extract-text-webpack-plugin": "~3.0.2",
71-
"uglifyjs-webpack-plugin": "~1.1.6",
72+
"uglifyjs-webpack-plugin": "~1.2.4",
7273
};
7374

7475
if (isAngular({packageJson})) {
7576
Object.assign(deps, {
7677
"@angular/compiler-cli": packageJson.dependencies["@angular/core"],
77-
"@ngtools/webpack": "~1.9.4",
78+
"@ngtools/webpack": "~6.0.0-rc.3",
79+
"@angular-devkit/core": "~0.5.5",
7880
});
7981
} else if (isTypeScript({packageJson})) {
80-
Object.assign(deps, { "awesome-typescript-loader": "~3.1.3" });
82+
Object.assign(deps, { "awesome-typescript-loader": "~5.0.0" });
8183
}
8284

8385
if (isSass({packageJson})) {

Diff for: lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function buildEnvData($projectData, platform, env) {
1919
const appResourcesPath = getAppResourcesPathFromProjectData($projectData);
2020
Object.assign(envData,
2121
appPath && { appPath },
22-
appResourcesPath && { appResourcesPath }
22+
appResourcesPath && { appResourcesPath },
2323
);
2424

2525
return envData;

Diff for: nativescript-target/NsJsonpChunkTemplatePlugin.js

+41-27
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,47 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var ConcatSource = require("webpack-sources").ConcatSource;
6-
var Template = require("webpack/lib/Template");
5+
"use strict";
76

8-
function JsonpChunkTemplatePlugin() { }
9-
module.exports = JsonpChunkTemplatePlugin;
10-
11-
JsonpChunkTemplatePlugin.prototype.apply = function (chunkTemplate) {
7+
const ConcatSource = require("webpack-sources").ConcatSource;
128

13-
//JSONP version
14-
chunkTemplate.plugin("render", function (modules, chunk) {
15-
var jsonpFunction = this.outputOptions.jsonpFunction;
16-
var source = new ConcatSource();
17-
source.add(jsonpFunction + "(" + JSON.stringify(chunk.ids) + ",");
18-
source.add(modules);
19-
var entries = [chunk.entryModule].filter(Boolean).map(function (m) {
20-
return m.id;
9+
class JsonpChunkTemplatePlugin {
10+
apply(chunkTemplate) {
11+
chunkTemplate.hooks.render.tap(
12+
"JsonpChunkTemplatePlugin",
13+
(modules, chunk) => {
14+
const jsonpFunction = chunkTemplate.outputOptions.jsonpFunction;
15+
const globalObject = chunkTemplate.outputOptions.globalObject;
16+
const source = new ConcatSource();
17+
source.add(
18+
`(${globalObject}[${JSON.stringify(jsonpFunction)}] = ${
19+
globalObject
20+
}[${JSON.stringify(jsonpFunction)}] || []).push([${JSON.stringify(
21+
chunk.ids
22+
)},`
23+
);
24+
source.add(modules);
25+
const entries = [chunk.entryModule].filter(Boolean).map(m =>
26+
[m.id].concat(
27+
Array.from(chunk.groupsIterable)[0]
28+
.chunks.filter(c => c !== chunk)
29+
.map(c => c.id)
30+
)
31+
);
32+
if (entries.length > 0) {
33+
source.add(`,${JSON.stringify(entries)}`);
34+
}
35+
source.add("])");
36+
return source;
37+
}
38+
);
39+
chunkTemplate.hooks.hash.tap("JsonpChunkTemplatePlugin", hash => {
40+
hash.update("JsonpChunkTemplatePlugin");
41+
hash.update("4");
42+
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
43+
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
2144
});
22-
if (entries.length > 0) {
23-
source.add("," + JSON.stringify(entries));
24-
}
25-
source.add(")");
26-
return source;
27-
});
28-
chunkTemplate.plugin("hash", function (hash) {
29-
hash.update("JsonpChunkTemplatePlugin");
30-
hash.update("3");
31-
hash.update(this.outputOptions.jsonpFunction + "");
32-
hash.update(this.outputOptions.library + "");
33-
});
34-
};
45+
}
46+
}
47+
module.exports = JsonpChunkTemplatePlugin;
48+

Diff for: nativescript-target/NsJsonpHotUpdateChunkTemplatePlugin.js

-27
This file was deleted.

0 commit comments

Comments
 (0)