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

Commit 4e622ae

Browse files
authored
Merge branch 'master' into dependencies
2 parents 76314ee + ae9cb8e commit 4e622ae

22 files changed

+231
-193
lines changed

Diff for: demo/AngularApp/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
}
1414
},
1515
"dependencies": {
16-
"@angular/common": "~7.2.0",
17-
"@angular/compiler": "~7.2.0",
18-
"@angular/core": "~7.2.0",
19-
"@angular/forms": "~7.2.0",
20-
"@angular/http": "~7.2.0",
21-
"@angular/platform-browser": "~7.2.0",
22-
"@angular/platform-browser-dynamic": "~7.2.0",
23-
"@angular/router": "~7.2.0",
16+
"@angular/common": "8.0.0",
17+
"@angular/compiler": "8.0.0",
18+
"@angular/core": "8.0.0",
19+
"@angular/forms": "8.0.0",
20+
"@angular/http": "8.0.0-beta.10",
21+
"@angular/platform-browser": "8.0.0",
22+
"@angular/platform-browser-dynamic": "8.0.0",
23+
"@angular/router": "8.0.0",
2424
"nativescript-angular": "next",
2525
"nativescript-theme-core": "~1.0.2",
2626
"reflect-metadata": "~0.1.8",
@@ -29,8 +29,8 @@
2929
"zone.js": "^0.8.4"
3030
},
3131
"devDependencies": {
32-
"@angular/compiler-cli": "~7.2.0",
33-
"@ngtools/webpack": "~7.2.0",
32+
"@angular/compiler-cli": "8.0.0",
33+
"@ngtools/webpack": "8.0.0",
3434
"@types/chai": "~4.1.7",
3535
"@types/mocha": "~5.2.5",
3636
"@types/node": "~10.12.18",
@@ -45,7 +45,7 @@
4545
"nativescript-dev-sass": "next",
4646
"nativescript-dev-typescript": "next",
4747
"nativescript-dev-webpack": "next",
48-
"typescript": "~3.1.1"
48+
"typescript": "~3.4.5"
4949
},
5050
"scripts": {
5151
"setup": "npm pack ../../ && npm i -D nativescript-dev-webpack*.tgz",

Diff for: demo/AngularApp/webpack.config.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = env => {
9191

9292
const ngCompilerPlugin = new AngularCompilerPlugin({
9393
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
94-
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
94+
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule), projectRoot)),
9595
mainPath: join(appFullPath, entryModule),
9696
tsConfigPath: join(__dirname, tsConfigName),
9797
skipCodeGeneration: !aot,
@@ -264,17 +264,7 @@ module.exports = env => {
264264
{ from: { glob: "**/*.jpg" } },
265265
{ from: { glob: "**/*.png" } },
266266
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
267-
// Generate a bundle starter script and activate it in package.json
268-
new nsWebpack.GenerateBundleStarterPlugin(
269-
// Don't include `runtime.js` when creating a snapshot. The plugin
270-
// configures the WebPack runtime to be generated inside the snapshot
271-
// module and no `runtime.js` module exist.
272-
(snapshot ? [] : ["./runtime"])
273-
.concat([
274-
"./vendor",
275-
"./bundle",
276-
])
277-
),
267+
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
278268
// For instructions on how to set up workers with webpack
279269
// check out https://github.com/nativescript/worker-loader
280270
new NativeScriptWorkerPlugin(),

Diff for: demo/JavaScriptApp/webpack.config.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,8 @@ module.exports = env => {
215215
{ from: { glob: "**/*.jpg" } },
216216
{ from: { glob: "**/*.png" } },
217217
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
218-
// Generate a bundle starter script and activate it in package.json
219-
new nsWebpack.GenerateBundleStarterPlugin(
220-
// Don't include `runtime.js` when creating a snapshot. The plugin
221-
// configures the WebPack runtime to be generated inside the snapshot
222-
// module and no `runtime.js` module exist.
223-
(snapshot ? [] : ["./runtime"])
224-
.concat([
225-
"./vendor",
226-
"./bundle",
227-
])
228-
),
218+
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
219+
229220
// For instructions on how to set up workers with webpack
230221
// check out https://github.com/nativescript/worker-loader
231222
new NativeScriptWorkerPlugin(),

Diff for: demo/TypeScriptApp/webpack.config.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const CleanWebpackPlugin = require("clean-webpack-plugin");
77
const CopyWebpackPlugin = require("copy-webpack-plugin");
8+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
89
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
910
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1011
const TerserPlugin = require("terser-webpack-plugin");
@@ -55,6 +56,9 @@ module.exports = env => {
5556
const entryModule = nsWebpack.getEntryModule(appFullPath, platform);
5657
const entryPath = `.${sep}${entryModule}.ts`;
5758
const entries = { bundle: entryPath, application: "./application.android" };
59+
60+
const tsConfigPath = resolve(projectRoot, "tsconfig.tns.json");
61+
5862
if (platform === "ios") {
5963
entries["tns_modules/tns-core-modules/inspector_modules"] = "inspector_modules.js";
6064
};
@@ -207,7 +211,8 @@ module.exports = env => {
207211
use: {
208212
loader: "ts-loader",
209213
options: {
210-
configFile: "tsconfig.tns.json",
214+
configFile: tsConfigPath,
215+
transpileOnly: !!hmr,
211216
allowTsInNodeModules: true,
212217
compilerOptions: {
213218
sourceMap: isAnySourceMapEnabled
@@ -231,17 +236,7 @@ module.exports = env => {
231236
{ from: { glob: "**/*.jpg" } },
232237
{ from: { glob: "**/*.png" } },
233238
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
234-
// Generate a bundle starter script and activate it in package.json
235-
new nsWebpack.GenerateBundleStarterPlugin(
236-
// Don't include `runtime.js` when creating a snapshot. The plugin
237-
// configures the WebPack runtime to be generated inside the snapshot
238-
// module and no `runtime.js` module exist.
239-
(snapshot ? [] : ["./runtime"])
240-
.concat([
241-
"./vendor",
242-
"./bundle",
243-
])
244-
),
239+
new nsWebpack.GenerateNativeScriptEntryPointsPlugin("bundle"),
245240
// For instructions on how to set up workers with webpack
246241
// check out https://github.com/nativescript/worker-loader
247242
new NativeScriptWorkerPlugin(),
@@ -290,6 +285,12 @@ module.exports = env => {
290285

291286
if (hmr) {
292287
config.plugins.push(new webpack.HotModuleReplacementPlugin());
288+
289+
// With HMR ts-loader should run in `transpileOnly` mode,
290+
// so assure type-checking with fork-ts-checker-webpack-plugin
291+
config.plugins.push(new ForkTsCheckerWebpackPlugin({
292+
tsconfig: tsConfigPath
293+
}));
293294
}
294295

295296

Diff for: dependencyManager.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can now bundle your project by passing --bundle flag to NativeScript CLI com
1717
- tns build ios --bundle
1818
- tns run android --bundle
1919
- tns run ios --bundle
20-
You can also pass the "--env.uglify" flag to use UglifyJS for minification.
20+
You can also pass the "--env.uglify" flag to use Terser for minification.
2121
For more information check out https://docs.nativescript.org/tooling/bundling-with-webpack#bundling.
2222
`;
2323

@@ -84,11 +84,11 @@ function getRequiredDeps(packageJson) {
8484
}
8585

8686
const deps = {
87-
"@angular/compiler-cli": "~7.2.0",
87+
"@angular/compiler-cli": "8.0.0",
8888
};
8989

9090
if (!dependsOn(packageJson, "@angular-devkit/build-angular")) {
91-
deps["@ngtools/webpack"] = "~7.2.0";
91+
deps["@ngtools/webpack"] = "8.0.0";
9292
}
9393

9494
return deps;

Diff for: package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-dev-webpack",
3-
"version": "0.23.0",
3+
"version": "0.25.0",
44
"main": "index",
55
"description": "",
66
"homepage": "http://www.telerik.com",
@@ -74,7 +74,7 @@
7474
"generate-android-snapshot": "./bin/generate-android-snapshot"
7575
},
7676
"dependencies": {
77-
"@angular-devkit/core": "~7.2.0",
77+
"@angular-devkit/core": "8.0.0",
7878
"clean-webpack-plugin": "~1.0.0",
7979
"copy-webpack-plugin": "~4.6.0",
8080
"css-loader": "~2.1.1",
@@ -89,7 +89,7 @@
8989
"resolve-url-loader": "~3.0.0",
9090
"sass-loader": "~7.1.0",
9191
"schema-utils": "0.4.5",
92-
"semver": "5.4.1",
92+
"semver": "^6.0.0",
9393
"shelljs": "0.6.0",
9494
"tapable": "1.0.0",
9595
"terser": "3.17.0",
@@ -101,16 +101,17 @@
101101
"webpack-sources": "~1.3.0"
102102
},
103103
"devDependencies": {
104-
"@ngtools/webpack": "~7.2.0",
105-
"@angular/compiler": "~7.2.0",
106-
"@angular/compiler-cli": "~7.2.0",
104+
"@angular/compiler": "8.0.0",
105+
"@angular/compiler-cli": "8.0.0",
106+
"@ngtools/webpack": "8.0.0",
107107
"@types/jasmine": "^3.3.7",
108108
"@types/node": "^10.12.12",
109109
"@types/proxyquire": "1.3.28",
110+
"@types/semver": "^6.0.0",
110111
"conventional-changelog-cli": "^1.3.22",
111112
"jasmine": "^3.2.0",
112113
"jasmine-spec-reporter": "^4.2.1",
113114
"proxyquire": "2.1.0",
114-
"typescript": "~3.1.1"
115+
"typescript": "~3.4.0"
115116
}
116117
}

Diff for: plugins/GenerateBundleStarterPlugin.js

+7-47
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,13 @@
1-
const { RawSource } = require("webpack-sources");
2-
const { getPackageJson } = require("../projectHelpers");
1+
const { GenerateNativeScriptEntryPointsPlugin } = require("./GenerateNativeScriptEntryPointsPlugin");
32

4-
exports.GenerateBundleStarterPlugin = (function() {
5-
function GenerateBundleStarterPlugin(bundles) {
6-
this.bundles = bundles;
7-
this.files = {};
3+
// backwards compatibility for <= 0.22 configs
4+
exports.GenerateBundleStarterPlugin = (function () {
5+
function GenerateBundleStarterPlugin() {
6+
this.entryPointsPlugin = new GenerateNativeScriptEntryPointsPlugin("bundle");
87
};
98

10-
GenerateBundleStarterPlugin.prototype.apply = function(compiler) {
11-
this.webpackContext = compiler.options.context;
12-
13-
compiler.hooks.emit.tapAsync("GenerateBundleStarterPlugin", (compilation, cb) => {
14-
this.addAsset(compilation, "package.json", this.generatePackageJson());
15-
this.addAsset(compilation, "starter.js", this.generateStarterModule());
16-
this.generateTnsJavaClasses(compilation);
17-
18-
cb();
19-
});
20-
}
21-
22-
GenerateBundleStarterPlugin.prototype.generateTnsJavaClasses = function (compilation) {
23-
const path = compilation.compiler.outputPath;
24-
const isAndroid = path.indexOf("android") > -1;
25-
26-
if (isAndroid && !compilation.assets["tns-java-classes.js"]) {
27-
this.addAsset(compilation, "tns-java-classes.js", "");
28-
}
29-
}
30-
31-
GenerateBundleStarterPlugin.prototype.generatePackageJson = function () {
32-
const packageJson = getPackageJson(this.webpackContext);
33-
packageJson.main = "starter";
34-
35-
return JSON.stringify(packageJson, null, 4);
36-
}
37-
38-
GenerateBundleStarterPlugin.prototype.generateStarterModule = function () {
39-
const moduleSource = this.bundles
40-
.map(bundle => `require("${bundle}")`)
41-
.join("\n");
42-
43-
return moduleSource;
44-
}
45-
46-
GenerateBundleStarterPlugin.prototype.addAsset = function(compilation, name, content) {
47-
if (this.files[name] !== content) {
48-
this.files[name] = content;
49-
compilation.assets[name] = new RawSource(content);
50-
}
9+
GenerateBundleStarterPlugin.prototype.apply = function (compiler) {
10+
this.entryPointsPlugin.apply(compiler);
5111
}
5212

5313
return GenerateBundleStarterPlugin;

Diff for: plugins/GenerateNativeScriptEntryPointsPlugin.js

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const { RawSource } = require("webpack-sources");
2+
const { getPackageJson } = require("../projectHelpers");
3+
const { SNAPSHOT_ENTRY_NAME } = require("./NativeScriptSnapshotPlugin");
4+
5+
6+
exports.GenerateNativeScriptEntryPointsPlugin = (function () {
7+
const GenerationFailedError = "Unable to generate entry files.";
8+
9+
function GenerateNativeScriptEntryPointsPlugin(appEntryName) {
10+
this.appEntryName = appEntryName;
11+
this.files = {};
12+
};
13+
14+
GenerateNativeScriptEntryPointsPlugin.prototype.apply = function (compiler) {
15+
this.webpackContext = compiler.options.context;
16+
17+
compiler.hooks.emit.tapAsync("GenerateNativeScriptEntryPointsPlugin", (compilation, cb) => {
18+
compilation.entrypoints.forEach(entryPoint => {
19+
this.generateEntryFile(compilation, entryPoint);
20+
});
21+
this.addAsset(compilation, "package.json", this.generatePackageJson());
22+
this.generateTnsJavaClasses(compilation);
23+
24+
cb();
25+
});
26+
}
27+
28+
GenerateNativeScriptEntryPointsPlugin.prototype.generateTnsJavaClasses = function (compilation) {
29+
const path = compilation.compiler.outputPath;
30+
const isAndroid = path.indexOf("android") > -1;
31+
32+
if (isAndroid && !compilation.assets["tns-java-classes.js"]) {
33+
this.addAsset(compilation, "tns-java-classes.js", ""); 0
34+
}
35+
}
36+
37+
GenerateNativeScriptEntryPointsPlugin.prototype.generatePackageJson = function () {
38+
const packageJson = getPackageJson(this.webpackContext);
39+
packageJson.main = this.appEntryName;
40+
41+
return JSON.stringify(packageJson, null, 4);
42+
}
43+
44+
GenerateNativeScriptEntryPointsPlugin.prototype.generateEntryFile = function (compilation, entryPoint) {
45+
const entryPointName = entryPoint.options.name;
46+
let entryChunk;
47+
if (entryPointName === SNAPSHOT_ENTRY_NAME) {
48+
// Do not require the snapshot entry dependencies as the snapshot will fail.
49+
return;
50+
}
51+
52+
const requireDeps =
53+
entryPoint.chunks.map(chunk => {
54+
let requireChunkFiles = "";
55+
if (chunk.name === entryPointName) {
56+
entryChunk = chunk;
57+
} else {
58+
chunk.files.forEach(fileName => {
59+
if (!this.isHMRFile(fileName)) {
60+
requireChunkFiles += `require("./${fileName}");`;
61+
}
62+
});
63+
}
64+
65+
return requireChunkFiles;
66+
}).join("");
67+
68+
if (!entryChunk) {
69+
throw new Error(`${GenerationFailedError} Entry chunk not found for entry "${entryPointName}".`);
70+
}
71+
72+
entryChunk.files.forEach(fileName => {
73+
if (!compilation.assets[fileName]) {
74+
throw new Error(`${GenerationFailedError} File "${fileName}" not found for entry "${entryPointName}".`);
75+
}
76+
77+
if (!this.isHMRFile(fileName)) {
78+
const currentEntryFileContent = compilation.assets[fileName].source();
79+
compilation.assets[fileName] = new RawSource(`${requireDeps}${currentEntryFileContent}`);
80+
}
81+
});
82+
}
83+
84+
GenerateNativeScriptEntryPointsPlugin.prototype.addAsset = function (compilation, name, content) {
85+
if (this.files[name] !== content) {
86+
this.files[name] = content;
87+
compilation.assets[name] = new RawSource(content);
88+
}
89+
}
90+
91+
GenerateNativeScriptEntryPointsPlugin.prototype.isHMRFile = function (fileName) {
92+
return fileName.indexOf("hot-update") > -1;
93+
}
94+
95+
return GenerateNativeScriptEntryPointsPlugin;
96+
})();

0 commit comments

Comments
 (0)