Skip to content

Commit 788f6a2

Browse files
committed
chore(renderer): update to webpack4 and NG 6
1 parent ed0d916 commit 788f6a2

File tree

5 files changed

+136
-69
lines changed

5 files changed

+136
-69
lines changed

e2e/renderer/app/vendor-platform.android.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

e2e/renderer/app/vendor-platform.ios.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

e2e/renderer/app/vendor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const appCssContext = require.context("~/", false, /^\.\/app\.(css|scss|less|sas
55
global.registerWebpackModules(appCssContext);
66
application.loadAppCss();
77

8-
require("./vendor-platform");
9-
108
require("reflect-metadata");
119
require("@angular/platform-browser");
1210
require("@angular/core");

e2e/renderer/package.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@
66
"nativescript": {
77
"id": "org.nativescript.renderer",
88
"tns-android": {
9-
"version": "3.4.1-2018-02-06-02"
9+
"version": "4.1.0-2018.4.13.1"
1010
}
1111
},
1212
"dependencies": {
13-
"@angular/common": "~5.2.0",
14-
"@angular/compiler": "~5.2.0",
15-
"@angular/core": "~5.2.0",
16-
"@angular/forms": "~5.2.0",
17-
"@angular/http": "~5.2.0",
18-
"@angular/platform-browser": "~5.2.0",
19-
"@angular/platform-browser-dynamic": "~5.2.0",
20-
"@angular/router": "~5.2.0",
13+
"@angular/common": "~6.0.0-rc.3",
14+
"@angular/compiler": "~6.0.0-rc.3",
15+
"@angular/core": "~6.0.0-rc.3",
16+
"@angular/forms": "~6.0.0-rc.3",
17+
"@angular/http": "~6.0.0-rc.3",
18+
"@angular/platform-browser": "~6.0.0-rc.3",
19+
"@angular/platform-browser-dynamic": "~6.0.0-rc.3",
20+
"@angular/router": "~6.0.0-rc.3",
2121
"nativescript-angular": "file:../../nativescript-angular",
2222
"nativescript-intl": "^3.0.0",
2323
"reflect-metadata": "~0.1.8",
24-
"rxjs": "^5.5.0",
24+
"rxjs": "~6.0.0-rc.1",
2525
"tns-core-modules": "next",
2626
"zone.js": "^0.8.4"
2727
},
2828
"devDependencies": {
29-
"@angular/compiler-cli": "~5.2.0",
30-
"@ngtools/webpack": "~1.9.4",
29+
"@angular-devkit/core": "~0.5.5",
30+
"@angular/compiler-cli": "~6.0.0-rc.3",
31+
"@ngtools/webpack": "~6.0.0-rc.3",
3132
"@types/chai": "^4.0.2",
3233
"@types/mocha": "^2.2.41",
3334
"@types/node": "^7.0.5",
@@ -36,25 +37,27 @@
3637
"babylon": "6.17.4",
3738
"chai": "~4.1.1",
3839
"chai-as-promised": "~7.1.1",
40+
"clean-webpack-plugin": "~0.1.19",
3941
"colors": "^1.1.2",
40-
"copy-webpack-plugin": "~4.3.0",
42+
"copy-webpack-plugin": "~4.5.1",
4143
"css-loader": "~0.28.7",
4244
"extract-text-webpack-plugin": "~3.0.2",
4345
"lazy": "1.0.11",
4446
"mocha": "~3.5.0",
4547
"mocha-junit-reporter": "^1.13.0",
4648
"mocha-multi": "^0.11.0",
4749
"nativescript-dev-appium": "next",
48-
"nativescript-dev-typescript": "~0.4.0",
49-
"nativescript-dev-webpack": "^0.9.2",
50+
"nativescript-dev-typescript": "~0.7.1",
51+
"nativescript-dev-webpack": "github:nativescript/nativescript-dev-webpack#sis0k0/webpack4",
5052
"nativescript-worker-loader": "~0.8.1",
5153
"raw-loader": "~0.5.1",
52-
"resolve-url-loader": "~2.2.1",
54+
"resolve-url-loader": "~2.3.0",
5355
"tslib": "^1.7.1",
54-
"typescript": "~2.6.2",
55-
"uglifyjs-webpack-plugin": "~1.1.6",
56-
"webpack": "~3.10.0",
56+
"typescript": "~2.7.2",
57+
"uglifyjs-webpack-plugin": "~1.2.4",
58+
"webpack": "~4.5.0",
5759
"webpack-bundle-analyzer": "^2.9.1",
60+
"webpack-cli": "~2.0.14",
5861
"webpack-sources": "~1.1.0"
5962
},
6063
"scripts": {

e2e/renderer/webpack.config.js

Lines changed: 114 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { resolve, join } = require("path");
1+
const { relative, resolve, join } = require("path");
22

33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6+
const CleanWebpackPlugin = require("clean-webpack-plugin");
67
const CopyWebpackPlugin = require("copy-webpack-plugin");
7-
const ExtractTextPlugin = require("extract-text-webpack-plugin");
88
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
99
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");
1010
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
@@ -14,23 +14,60 @@ module.exports = env => {
1414
if (!platform) {
1515
throw new Error("You need to provide a target platform!");
1616
}
17+
1718
const platforms = ["ios", "android"];
18-
const { snapshot, uglify, report, aot } = env;
19-
const ngToolsWebpackOptions = { tsConfigPath: "tsconfig.json" };
19+
const projectRoot = __dirname;
20+
// Default destination inside platforms/<platform>/...
21+
const dist = resolve(projectRoot, nsWebpack.getAppPath(platform));
22+
const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS";
23+
24+
const {
25+
// The 'appPath' and 'appResourcesPath' values are fetched from
26+
// the nsconfig.json configuration file
27+
// when bundling with `tns run android|ios --bundle`.
28+
appPath = "app",
29+
appResourcesPath = "app/App_Resources",
30+
31+
// Aot, snapshot, uglify and report can be enabled by providing
32+
// the `--env.snapshot`, `--env.uglify` or `--env.report` flags
33+
// when running 'tns run android|ios'
34+
aot,
35+
snapshot,
36+
uglify,
37+
report,
38+
} = env;
39+
const ngToolsWebpackOptions = { tsConfigPath: join(__dirname, "tsconfig.json") };
40+
41+
const appFullPath = resolve(projectRoot, appPath);
42+
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
43+
44+
const entryModule = aot ?
45+
nsWebpack.getAotEntryModule(appFullPath) :
46+
`${nsWebpack.getEntryModule(appFullPath)}.ts`;
47+
const entryPath = `./${entryModule}`;
48+
const vendorPath = `./vendor.ts`;
2049

2150
const config = {
22-
context: resolve("./app"),
51+
mode: "development",
52+
context: appFullPath,
53+
watchOptions: {
54+
ignored: [
55+
appResourcesFullPath,
56+
// Don't watch hidden files
57+
"**/.*",
58+
]
59+
},
2360
target: nativescriptTarget,
2461
entry: {
25-
bundle: aot ? "./main.aot.ts" : "./main.ts",
26-
vendor: "./vendor",
62+
bundle: entryPath,
63+
vendor: vendorPath,
2764
},
2865
output: {
2966
pathinfo: true,
30-
// Default destination inside platforms/<platform>/...
31-
path: resolve(nsWebpack.getAppPath(platform)),
67+
path: dist,
3268
libraryTarget: "commonjs2",
3369
filename: "[name].js",
70+
globalObject: "global",
3471
},
3572
resolve: {
3673
extensions: [".ts", ".js", ".scss", ".css"],
@@ -40,7 +77,7 @@ module.exports = env => {
4077
"node_modules",
4178
],
4279
alias: {
43-
'~': resolve("./app")
80+
'~': appFullPath
4481
},
4582
// don't resolve symlinks to symlinked modules
4683
symlinks: false
@@ -55,6 +92,30 @@ module.exports = env => {
5592
"timers": false,
5693
"setImmediate": false,
5794
"fs": "empty",
95+
"__dirname": false,
96+
},
97+
devtool: "none",
98+
optimization: {
99+
runtimeChunk: { name: "vendor" },
100+
splitChunks: {
101+
cacheGroups: {
102+
common: {
103+
name: "common",
104+
chunks: "all",
105+
test: /vendor/,
106+
enforce: true,
107+
},
108+
}
109+
},
110+
minimize: !!uglify,
111+
minimizer: [
112+
// Override default minimizer to work around an Android issue by setting compress = false
113+
new UglifyJsPlugin({
114+
uglifyOptions: {
115+
compress: platform !== "android"
116+
}
117+
})
118+
],
58119
},
59120
module: {
60121
rules: [
@@ -81,32 +142,40 @@ module.exports = env => {
81142
{ test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
82143

83144
// Compile TypeScript files with ahead-of-time compiler.
84-
{ test: /.ts$/, use: [
85-
"nativescript-dev-webpack/moduleid-compat-loader",
86-
{ loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
87-
]},
145+
{
146+
test: /.ts$/, use: [
147+
"nativescript-dev-webpack/moduleid-compat-loader",
148+
{ loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
149+
]
150+
},
88151
],
89152
},
90153
plugins: [
91-
// Vendor libs go to the vendor.js chunk
92-
new webpack.optimize.CommonsChunkPlugin({
93-
name: ["vendor"],
94-
}),
95154
// Define useful constants like TNS_WEBPACK
96155
new webpack.DefinePlugin({
97156
"global.TNS_WEBPACK": "true",
98157
}),
158+
// Remove all files from the out dir.
159+
new CleanWebpackPlugin([`${dist}/**/*`]),
160+
// Copy native app resources to out dir.
161+
new CopyWebpackPlugin([
162+
{
163+
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
164+
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
165+
context: projectRoot
166+
},
167+
]),
99168
// Copy assets to out dir. Add your own globs as needed.
100169
new CopyWebpackPlugin([
101-
{ from: "App_Resources/**" },
102170
{ from: "fonts/**" },
103171
{ from: "**/*.jpg" },
104172
{ from: "**/*.png" },
105173
{ from: "**/*.xml" },
106-
]),
174+
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
107175
// Generate a bundle starter script and activate it in package.json
108176
new nsWebpack.GenerateBundleStarterPlugin([
109177
"./vendor",
178+
"./common",
110179
"./bundle",
111180
]),
112181
// Support for web workers since v3.2
@@ -119,45 +188,52 @@ module.exports = env => {
119188
platformOptions: {
120189
platform,
121190
platforms,
122-
// ignore: ["App_Resources"]
123191
},
124192
}, ngToolsWebpackOptions)
125193
),
126194
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
127195
new nsWebpack.WatchStateLoggerPlugin(),
128196
],
129197
};
198+
199+
if (platform === "android") {
200+
// Add your custom Activities, Services and other android app components here.
201+
const appComponents = [
202+
"tns-core-modules/ui/frame",
203+
"tns-core-modules/ui/frame/activity",
204+
];
205+
206+
// Require all Android app components
207+
// in the entry module (bundle.ts) and the vendor module (vendor.ts).
208+
config.module.rules.unshift({
209+
test: new RegExp(`${entryPath}|${vendorPath}`),
210+
use: {
211+
loader: "nativescript-dev-webpack/android-app-components-loader",
212+
options: { modules: appComponents }
213+
}
214+
});
215+
}
216+
130217
if (report) {
131218
// Generate report files for bundles content
132219
config.plugins.push(new BundleAnalyzerPlugin({
133220
analyzerMode: "static",
134221
openAnalyzer: false,
135222
generateStatsFile: true,
136-
reportFilename: join(__dirname, "report", `report.html`),
137-
statsFilename: join(__dirname, "report", `stats.json`),
223+
reportFilename: resolve(projectRoot, "report", `report.html`),
224+
statsFilename: resolve(projectRoot, "report", `stats.json`),
138225
}));
139226
}
227+
140228
if (snapshot) {
141229
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
142-
chunk: "vendor",
143-
projectRoot: __dirname,
230+
chunks: [ "vendor", "common" ],
231+
projectRoot,
144232
webpackConfig: config,
145233
targetArchs: ["arm", "arm64", "ia32"],
146-
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
147234
useLibs: false
148235
}));
149236
}
150-
if (uglify) {
151-
config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));
152-
153-
// Work around an Android issue by setting compress = false
154-
const compress = platform !== "android";
155-
config.plugins.push(new UglifyJsPlugin({
156-
uglifyOptions: {
157-
mangle: { reserved: nsWebpack.uglifyMangleExcludes },
158-
compress,
159-
}
160-
}));
161-
}
237+
162238
return config;
163239
};

0 commit comments

Comments
 (0)