Skip to content

Commit 392c626

Browse files
chore: Update nativescript-dev-webpack package and related files
1 parent 7686d64 commit 392c626

File tree

3 files changed

+80
-42
lines changed

3 files changed

+80
-42
lines changed

sdkAngular/app/vendor-platform.android.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ if (!global["__snapshot"]) {
88
require("ui/frame/activity");
99
require("./main-activity.android.ts");
1010
}
11-

sdkAngular/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
"zone.js": "~0.8.2"
4444
},
4545
"devDependencies": {
46-
"uglifyjs-webpack-plugin": "^1.1.6",
4746
"@angular/compiler-cli": "^5.0.0",
4847
"@ngtools/webpack": "~1.8.2",
4948
"babel-traverse": "6.24.1",
5049
"babel-types": "6.24.1",
5150
"babylon": "6.17.0",
5251
"chai": "^3.5.0",
52+
"clean-webpack-plugin": "~0.1.19",
5353
"codelyzer": "^3.0.0",
5454
"copy-webpack-plugin": "~4.0.1",
5555
"css-loader": "~0.28.7",
@@ -63,18 +63,18 @@
6363
"mocha": "^3.3.0",
6464
"nativescript-css-loader": "~0.26.0",
6565
"nativescript-dev-typescript": "0.5.1",
66-
"nativescript-dev-webpack": "next",
66+
"nativescript-dev-webpack": "^0.10.1",
6767
"nativescript-worker-loader": "~0.8.1",
6868
"raw-loader": "~0.5.1",
6969
"resolve-url-loader": "~2.1.0",
7070
"tns-platform-declarations": "3.4.0",
7171
"tslib": "1.7.1",
7272
"tslint": "^5.1.0",
7373
"typescript": "~2.4.2",
74+
"uglifyjs-webpack-plugin": "^1.1.6",
7475
"webpack": "~3.8.1",
7576
"webpack-bundle-analyzer": "^2.8.2",
76-
"webpack-sources": "~1.0.1",
77-
"clean-webpack-plugin": "~0.1.19"
77+
"webpack-sources": "~1.0.1"
7878
},
7979
"scripts": {
8080
"tslint": "tslint --project tsconfig.json --config tslint.json",

sdkAngular/webpack.config.js

+76-37
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,25 +14,52 @@ 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") };
2040

21-
const nativeClassExtenders = [
22-
join(__dirname, "app/main-activity.android.ts"),
23-
];
41+
const appFullPath = resolve(projectRoot, appPath);
42+
const appResourcesFullPath = resolve(projectRoot, appResourcesPath);
2443

2544
const config = {
26-
context: resolve("./app"),
45+
context: appFullPath,
46+
watchOptions: {
47+
ignored: [
48+
appResourcesFullPath,
49+
// Don't watch hidden files
50+
"**/.*",
51+
]
52+
},
2753
target: nativescriptTarget,
2854
entry: {
29-
bundle: aot ? "./main.aot.ts" : "./main.ts",
55+
bundle: aot ?
56+
`./${nsWebpack.getAotEntryModule(appFullPath)}` :
57+
`./${nsWebpack.getEntryModule(appFullPath)}`,
3058
vendor: "./vendor",
3159
},
3260
output: {
3361
pathinfo: true,
34-
// Default destination inside platforms/<platform>/...
35-
path: resolve(nsWebpack.getAppPath(platform)),
62+
path: dist,
3663
libraryTarget: "commonjs2",
3764
filename: "[name].js",
3865
},
@@ -44,7 +71,7 @@ module.exports = env => {
4471
"node_modules",
4572
],
4673
alias: {
47-
'~': resolve("./app")
74+
'~': appFullPath
4875
},
4976
// don't resolve symlinks to symlinked modules
5077
symlinks: false
@@ -65,15 +92,30 @@ module.exports = env => {
6592
{ test: /\.html$|\.xml$/, use: "raw-loader" },
6693

6794
// tns-core-modules reads the app.css and its imports using css-loader
68-
{ test: /\/app\.css$/, use: "css-loader?url=false" },
69-
{ test: /\/app\.scss$/, use: ["css-loader?url=false", "sass-loader"] },
95+
{
96+
test: /[\/|\\]app\.css$/,
97+
use: {
98+
loader: "css-loader",
99+
options: { minimize: false, url: false },
100+
}
101+
},
102+
{
103+
test: /[\/|\\]app\.scss$/,
104+
use: [
105+
{ loader: "css-loader", options: { minimize: false, url: false } },
106+
"sass-loader"
107+
]
108+
},
70109

71110
// Angular components reference css files and their imports using raw-loader
72-
{ test: /\.css$/, exclude: /\/app\.css$/, use: "raw-loader" },
73-
{ test: /\.scss$/, exclude: /\/app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
111+
{ test: /\.css$/, exclude: /[\/|\\]app\.css$/, use: "raw-loader" },
112+
{ test: /\.scss$/, exclude: /[\/|\\]app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },
74113

75114
// Compile TypeScript files with ahead-of-time compiler.
76-
{ test: /.ts$/, use: ["nativescript-dev-webpack/moduleid-compat-loader", "@ngtools/webpack"] },
115+
{ test: /.ts$/, use: [
116+
"nativescript-dev-webpack/moduleid-compat-loader",
117+
{ loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
118+
]},
77119
],
78120
},
79121
plugins: [
@@ -85,16 +127,23 @@ module.exports = env => {
85127
new webpack.DefinePlugin({
86128
"global.TNS_WEBPACK": "true",
87129
}),
130+
// Remove all files from the out dir.
131+
new CleanWebpackPlugin([ `${dist}/**/*` ]),
132+
// Copy native app resources to out dir.
133+
new CopyWebpackPlugin([
134+
{
135+
from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,
136+
to: `${dist}/App_Resources/${appResourcesPlatformDir}`,
137+
context: projectRoot
138+
},
139+
]),
88140
// Copy assets to out dir. Add your own globs as needed.
89141
new CopyWebpackPlugin([
90-
{ from: "App_Resources/**" },
91142
{ from: "fonts/**" },
92143
{ from: "**/*.jpg" },
93144
{ from: "**/*.png" },
94145
{ from: "**/*.xml" },
95-
{ from: "**/person-model.json" },
96-
{ from: "**/person-metadata.json" },
97-
]),
146+
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
98147
// Generate a bundle starter script and activate it in package.json
99148
new nsWebpack.GenerateBundleStarterPlugin([
100149
"./vendor",
@@ -105,7 +154,7 @@ module.exports = env => {
105154
// AngularCompilerPlugin with augmented NativeScript filesystem to handle platform specific resource resolution.
106155
new nsWebpack.NativeScriptAngularCompilerPlugin(
107156
Object.assign({
108-
entryModule: resolve(__dirname, "app/app.module#AppModule"),
157+
entryModule: resolve(appPath, "app.module#AppModule"),
109158
skipCodeGeneration: !aot,
110159
platformOptions: {
111160
platform,
@@ -124,20 +173,17 @@ module.exports = env => {
124173
analyzerMode: "static",
125174
openAnalyzer: false,
126175
generateStatsFile: true,
127-
reportFilename: join(__dirname, "report", `report.html`),
128-
statsFilename: join(__dirname, "report", `stats.json`),
176+
reportFilename: resolve(projectRoot, "report", `report.html`),
177+
statsFilename: resolve(projectRoot, "report", `stats.json`),
129178
}));
130179
}
131180
if (snapshot) {
132181
config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
133182
chunk: "vendor",
134-
projectRoot: __dirname,
183+
projectRoot,
135184
webpackConfig: config,
136185
targetArchs: ["arm", "arm64", "ia32"],
137-
tnsJavaClassesOptions: {
138-
packages: ["tns-core-modules" ],
139-
modules: nativeClassExtenders,
140-
},
186+
tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
141187
useLibs: false
142188
}));
143189
}
@@ -148,17 +194,10 @@ module.exports = env => {
148194
const compress = platform !== "android";
149195
config.plugins.push(new UglifyJsPlugin({
150196
uglifyOptions: {
151-
mangle: {
152-
reserved: [
153-
...nsWebpack.uglifyMangleExcludes,
154-
"org.nativescript.sdkAngular.MainActivity",
155-
"AutoCompleteAdapter",
156-
],
157-
},
197+
mangle: { reserved: nsWebpack.uglifyMangleExcludes }, // Deprecated. Remove if using {N} 4+.
158198
compress,
159199
}
160200
}));
161201
}
162-
163202
return config;
164203
};

0 commit comments

Comments
 (0)