Skip to content

Commit e0d535b

Browse files
committed
Upgrade demos to NS5.2
1 parent c5a3ec1 commit e0d535b

File tree

4 files changed

+66
-41
lines changed

4 files changed

+66
-41
lines changed

demo-angular/package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,40 @@
99
"tslint": "tslint **/*.ts --config ../tslint.json"
1010
},
1111
"dependencies": {
12-
"@angular/animations": "~7.0.0",
13-
"@angular/common": "~7.0.0",
14-
"@angular/compiler": "~7.0.0",
15-
"@angular/core": "~7.0.0",
16-
"@angular/forms": "~7.0.0",
17-
"@angular/http": "~7.0.0",
18-
"@angular/platform-browser": "~7.0.0",
19-
"@angular/platform-browser-dynamic": "~7.0.0",
20-
"@angular/router": "~7.0.0",
21-
"nativescript-angular": "^7.0.0",
12+
"@angular/animations": "~7.2.0",
13+
"@angular/common": "~7.2.0",
14+
"@angular/compiler": "~7.2.0",
15+
"@angular/core": "~7.2.0",
16+
"@angular/forms": "~7.2.0",
17+
"@angular/http": "~7.2.0",
18+
"@angular/platform-browser": "~7.2.0",
19+
"@angular/platform-browser-dynamic": "~7.2.0",
20+
"@angular/router": "~7.2.0",
21+
"nativescript-angular": "^7.2.2",
2222
"nativescript-localize": "file:../src",
2323
"nativescript-theme-core": "~1.0.4",
2424
"reflect-metadata": "^0.1.12",
2525
"rxjs": "^6.3.3",
26-
"tns-core-modules": "^5.0.2",
27-
"zone.js": "^0.8.26"
26+
"tns-core-modules": "^5.2.1",
27+
"zone.js": "^0.8.4"
2828
},
2929
"devDependencies": {
30-
"@angular/compiler-cli": "~7.0.0",
31-
"@nativescript/schematics": "^0.3.4",
32-
"@ngtools/webpack": "~7.0.0",
33-
"nativescript-dev-typescript": "^0.7.6",
34-
"nativescript-dev-webpack": "^0.18.0",
30+
"@angular/compiler-cli": "~7.2.0",
31+
"@nativescript/schematics": "^0.5.1",
32+
"@ngtools/webpack": "~7.2.0",
33+
"nativescript-dev-typescript": "^0.8.0",
34+
"nativescript-dev-webpack": "^0.20.2",
3535
"tns-platform-declarations": "^5.0.2",
3636
"tslint": "^5.8.0",
3737
"typescript": "~3.1.1"
3838
},
3939
"nativescript": {
4040
"id": "org.nativescript.demo.angular",
4141
"tns-ios": {
42-
"version": "5.0.0"
42+
"version": "5.2.0"
4343
},
4444
"tns-android": {
45-
"version": "5.0.0"
45+
"version": "5.2.0"
4646
}
4747
}
4848
}

demo-angular/webpack.config.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const { join, relative, resolve, sep } = require("path");
1+
const { join, relative, resolve, sep, dirname } = require("path");
22

33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
66
const { nsReplaceBootstrap } = require("nativescript-dev-webpack/transformers/ns-replace-bootstrap");
7+
const { nsReplaceLazyLoader } = require("nativescript-dev-webpack/transformers/ns-replace-lazy-loader");
8+
const { nsSupportHmrNg } = require("nativescript-dev-webpack/transformers/ns-support-hmr-ng");
9+
const { getMainModulePath } = require("nativescript-dev-webpack/utils/ast-utils");
710
const CleanWebpackPlugin = require("clean-webpack-plugin");
811
const CopyWebpackPlugin = require("copy-webpack-plugin");
912
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
@@ -33,8 +36,8 @@ module.exports = env => {
3336
// The 'appPath' and 'appResourcesPath' values are fetched from
3437
// the nsconfig.json configuration file
3538
// when bundling with `tns run android|ios --bundle`.
36-
appPath = "app",
37-
appResourcesPath = "app/App_Resources",
39+
appPath = "src",
40+
appResourcesPath = "App_Resources",
3841

3942
// You can provide the following flags when running 'tns run android|ios'
4043
aot, // --env.aot
@@ -44,23 +47,45 @@ module.exports = env => {
4447
sourceMap, // --env.sourceMap
4548
hmr, // --env.hmr,
4649
} = env;
47-
const externals = (env.externals || []).map((e) => { // --env.externals
48-
return new RegExp(e + ".*");
49-
});
5050

51+
const externals = nsWebpack.getConvertedExternals(env.externals);
5152
const appFullPath = resolve(projectRoot, appPath);
5253
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
53-
54+
const tsConfigName = "tsconfig.tns.json";
5455
const entryModule = `${nsWebpack.getEntryModule(appFullPath)}.ts`;
5556
const entryPath = `.${sep}${entryModule}`;
57+
const ngCompilerTransformers = [];
58+
const additionalLazyModuleResources = [];
59+
if (aot) {
60+
ngCompilerTransformers.push(nsReplaceBootstrap);
61+
}
62+
63+
if (hmr) {
64+
ngCompilerTransformers.push(nsSupportHmrNg);
65+
}
66+
67+
// when "@angular/core" is external, it's not included in the bundles. In this way, it will be used
68+
// directly from node_modules and the Angular modules loader won't be able to resolve the lazy routes
69+
// fixes https://github.com/NativeScript/nativescript-cli/issues/4024
70+
if (env.externals && env.externals.indexOf("@angular/core") > -1) {
71+
const appModuleRelativePath = getMainModulePath(resolve(appFullPath, entryModule), tsConfigName);
72+
if (appModuleRelativePath) {
73+
const appModuleFolderPath = dirname(resolve(appFullPath, appModuleRelativePath));
74+
// include the lazy loader inside app module
75+
ngCompilerTransformers.push(nsReplaceLazyLoader);
76+
// include the new lazy loader path in the allowed ones
77+
additionalLazyModuleResources.push(appModuleFolderPath);
78+
}
79+
}
5680

5781
const ngCompilerPlugin = new AngularCompilerPlugin({
5882
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
59-
platformTransformers: aot ? [nsReplaceBootstrap(() => ngCompilerPlugin)] : null,
83+
platformTransformers: ngCompilerTransformers.map(t => t(() => ngCompilerPlugin, resolve(appFullPath, entryModule))),
6084
mainPath: resolve(appPath, entryModule),
61-
tsConfigPath: join(__dirname, "tsconfig.tns.json"),
85+
tsConfigPath: join(__dirname, tsConfigName),
6286
skipCodeGeneration: !aot,
6387
sourceMap: !!sourceMap,
88+
additionalLazyModuleResources: additionalLazyModuleResources
6489
});
6590

6691
const config = {
@@ -171,14 +196,15 @@ module.exports = env => {
171196
// tns-core-modules reads the app.css and its imports using css-loader
172197
{
173198
test: /[\/|\\]app\.css$/,
174-
use: {
175-
loader: "css-loader",
176-
options: { minimize: false, url: false },
177-
}
199+
use: [
200+
"nativescript-dev-webpack/style-hot-loader",
201+
{ loader: "css-loader", options: { minimize: false, url: false } }
202+
]
178203
},
179204
{
180205
test: /[\/|\\]app\.scss$/,
181206
use: [
207+
"nativescript-dev-webpack/style-hot-loader",
182208
{ loader: "css-loader", options: { minimize: false, url: false } },
183209
"sass-loader"
184210
]
@@ -192,6 +218,7 @@ module.exports = env => {
192218
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
193219
use: [
194220
"nativescript-dev-webpack/moduleid-compat-loader",
221+
"nativescript-dev-webpack/lazy-ngmodule-hot-loader",
195222
"@ngtools/webpack",
196223
]
197224
},

demo/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
"dependencies": {
99
"nativescript-localize": "file:../src",
1010
"nativescript-theme-core": "^1.0.4",
11-
"nativescript-unit-test-runner": "^0.3.4",
12-
"tns-core-modules": "^5.0.2"
11+
"nativescript-unit-test-runner": "^0.5.0",
12+
"tns-core-modules": "^5.2.1"
1313
},
1414
"devDependencies": {
1515
"jasmine-core": "^3.3.0",
16-
"karma": "^3.1.1",
16+
"karma": "^4.0.0",
1717
"karma-jasmine": "^2.0.1",
1818
"karma-nativescript-launcher": "^0.4.0",
19-
"nativescript-dev-webpack": "^0.18.0",
19+
"nativescript-dev-webpack": "^0.20.2",
2020
"tslint": "^5.8.0"
2121
},
2222
"nativescript": {
2323
"id": "org.nativescript.demo.javascript",
2424
"tns-ios": {
25-
"version": "5.0.0"
25+
"version": "5.2.0"
2626
},
2727
"tns-android": {
28-
"version": "5.0.0"
28+
"version": "5.2.0"
2929
}
3030
}
3131
}

demo/webpack.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ module.exports = env => {
4242
sourceMap, // --env.sourceMap
4343
hmr, // --env.hmr,
4444
} = env;
45-
const externals = (env.externals || []).map((e) => { // --env.externals
46-
return new RegExp(e + ".*");
47-
});
45+
const externals = nsWebpack.getConvertedExternals(env.externals);
4846

4947
const appFullPath = resolve(projectRoot, appPath);
5048
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);

0 commit comments

Comments
 (0)