@@ -11,9 +11,9 @@ const CleanWebpackPlugin = require("clean-webpack-plugin");
11
11
const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
12
12
const { BundleAnalyzerPlugin } = require ( "webpack-bundle-analyzer" ) ;
13
13
const { NativeScriptWorkerPlugin } = require ( "nativescript-worker-loader/NativeScriptWorkerPlugin" ) ;
14
- const UglifyJsPlugin = require ( "uglifyjs -webpack-plugin" ) ;
15
- const { AngularCompilerPlugin } = require ( "@ngtools/ webpack" ) ;
16
- const hashSalt = Date . now ( ) . toString ( ) ;
14
+ const TerserPlugin = require ( "terser -webpack-plugin" ) ;
15
+ const { getAngularCompilerPlugin } = require ( "nativescript-dev- webpack/plugins/NativeScriptAngularCompilerPlugin " ) ;
16
+ const hashSalt = Date . now ( ) . toString ( ) ;
17
17
18
18
module . exports = env => {
19
19
// Add your custom Activities, Services and other Android app components here.
@@ -27,6 +27,7 @@ module.exports = env => {
27
27
throw new Error ( "You need to provide a target platform!" ) ;
28
28
}
29
29
30
+ const AngularCompilerPlugin = getAngularCompilerPlugin ( platform ) ;
30
31
const projectRoot = __dirname ;
31
32
32
33
// Default destination inside platforms/<platform>/...
@@ -46,15 +47,23 @@ module.exports = env => {
46
47
uglify, // --env.uglify
47
48
report, // --env.report
48
49
sourceMap, // --env.sourceMap
50
+ hiddenSourceMap, // --env.hiddenSourceMap
49
51
hmr, // --env.hmr,
52
+ unitTesting, // --env.unitTesting
50
53
} = env ;
51
54
55
+ const isAnySourceMapEnabled = ! ! sourceMap || ! ! hiddenSourceMap ;
52
56
const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
53
57
const appFullPath = resolve ( projectRoot , appPath ) ;
54
58
const appResourcesFullPath = resolve ( projectRoot , appResourcesPath ) ;
55
59
const tsConfigName = "tsconfig.tns.json" ;
56
- const entryModule = `${ nsWebpack . getEntryModule ( appFullPath ) } .ts` ;
60
+ const entryModule = `${ nsWebpack . getEntryModule ( appFullPath , platform ) } .ts` ;
57
61
const entryPath = `.${ sep } ${ entryModule } ` ;
62
+ const entries = { bundle : entryPath } ;
63
+ if ( platform === "ios" ) {
64
+ entries [ "tns_modules/tns-core-modules/inspector_modules" ] = "inspector_modules.js" ;
65
+ } ;
66
+
58
67
const ngCompilerTransformers = [ ] ;
59
68
const additionalLazyModuleResources = [ ] ;
60
69
if ( aot ) {
@@ -82,13 +91,15 @@ module.exports = env => {
82
91
const ngCompilerPlugin = new AngularCompilerPlugin ( {
83
92
hostReplacementPaths : nsWebpack . getResolver ( [ platform , "tns" ] ) ,
84
93
platformTransformers : ngCompilerTransformers . map ( t => t ( ( ) => ngCompilerPlugin , resolve ( appFullPath , entryModule ) ) ) ,
85
- mainPath : resolve ( appPath , entryModule ) ,
94
+ mainPath : join ( appFullPath , entryModule ) ,
86
95
tsConfigPath : join ( __dirname , tsConfigName ) ,
87
96
skipCodeGeneration : ! aot ,
88
- sourceMap : ! ! sourceMap ,
97
+ sourceMap : ! ! isAnySourceMapEnabled ,
89
98
additionalLazyModuleResources : additionalLazyModuleResources
90
99
} ) ;
91
100
101
+ let sourceMapFilename = nsWebpack . getSourceMapFilename ( hiddenSourceMap , __dirname , dist ) ;
102
+
92
103
const config = {
93
104
mode : uglify ? "production" : "development" ,
94
105
context : appFullPath ,
@@ -101,12 +112,11 @@ module.exports = env => {
101
112
]
102
113
} ,
103
114
target : nativescriptTarget ,
104
- entry : {
105
- bundle : entryPath ,
106
- } ,
115
+ entry : entries ,
107
116
output : {
108
117
pathinfo : false ,
109
118
path : dist ,
119
+ sourceMapFilename,
110
120
libraryTarget : "commonjs2" ,
111
121
filename : "[name].js" ,
112
122
globalObject : "global" ,
@@ -137,8 +147,9 @@ module.exports = env => {
137
147
"fs" : "empty" ,
138
148
"__dirname" : false ,
139
149
} ,
140
- devtool : sourceMap ? "inline-source-map" : "none" ,
150
+ devtool : hiddenSourceMap ? "hidden-source-map" : ( sourceMap ? "inline-source-map" : "none" ) ,
141
151
optimization : {
152
+ runtimeChunk : "single" ,
142
153
splitChunks : {
143
154
cacheGroups : {
144
155
vendor : {
@@ -155,12 +166,14 @@ module.exports = env => {
155
166
} ,
156
167
minimize : ! ! uglify ,
157
168
minimizer : [
158
- new UglifyJsPlugin ( {
169
+ new TerserPlugin ( {
159
170
parallel : true ,
160
171
cache : true ,
161
- uglifyOptions : {
172
+ sourceMap : isAnySourceMapEnabled ,
173
+ terserOptions : {
162
174
output : {
163
175
comments : false ,
176
+ semicolons : ! isAnySourceMapEnabled
164
177
} ,
165
178
compress : {
166
179
// The Android SBG has problems parsing the output
@@ -175,7 +188,7 @@ module.exports = env => {
175
188
module : {
176
189
rules : [
177
190
{
178
- test : new RegExp ( entryPath ) ,
191
+ test : nsWebpack . getEntryPathRegExp ( appFullPath , entryPath ) ,
179
192
use : [
180
193
// Require all Android app components
181
194
platform === "android" && {
@@ -188,6 +201,9 @@ module.exports = env => {
188
201
options : {
189
202
angular : true ,
190
203
loadCss : ! snapshot , // load the application css if in debug mode
204
+ unitTesting,
205
+ appFullPath,
206
+ projectRoot,
191
207
}
192
208
} ,
193
209
] . filter ( loader => ! ! loader )
@@ -200,14 +216,14 @@ module.exports = env => {
200
216
test : / [ \/ | \\ ] a p p \. c s s $ / ,
201
217
use : [
202
218
"nativescript-dev-webpack/style-hot-loader" ,
203
- { loader : "css-loader" , options : { minimize : false , url : false } }
219
+ { loader : "css-loader" , options : { url : false } }
204
220
]
205
221
} ,
206
222
{
207
223
test : / [ \/ | \\ ] a p p \. s c s s $ / ,
208
224
use : [
209
225
"nativescript-dev-webpack/style-hot-loader" ,
210
- { loader : "css-loader" , options : { minimize : false , url : false } } ,
226
+ { loader : "css-loader" , options : { url : false } } ,
211
227
"sass-loader"
212
228
]
213
229
} ,
@@ -239,8 +255,6 @@ module.exports = env => {
239
255
"global.TNS_WEBPACK" : "true" ,
240
256
"process" : undefined ,
241
257
} ) ,
242
- // Remove all files from the out dir.
243
- new CleanWebpackPlugin ( [ `${ dist } /**/*` ] ) ,
244
258
// Copy native app resources to out dir.
245
259
new CopyWebpackPlugin ( [
246
260
{
@@ -249,6 +263,7 @@ module.exports = env => {
249
263
context : projectRoot
250
264
} ,
251
265
] ) ,
266
+
252
267
// Copy assets to out dir. Add your own globs as needed.
253
268
new CopyWebpackPlugin ( [
254
269
{ from : { glob : "ng-ui-widgets-category/web-view/web-view-html/*.html" } } ,
@@ -257,10 +272,16 @@ module.exports = env => {
257
272
{ from : { glob : "**/*.png" } } ,
258
273
] , { ignore : [ `${ relative ( appPath , appResourcesFullPath ) } /**` ] } ) ,
259
274
// Generate a bundle starter script and activate it in package.json
260
- new nsWebpack . GenerateBundleStarterPlugin ( [
261
- "./vendor" ,
262
- "./bundle" ,
263
- ] ) ,
275
+ new nsWebpack . GenerateBundleStarterPlugin (
276
+ // Don't include `runtime.js` when creating a snapshot. The plugin
277
+ // configures the WebPack runtime to be generated inside the snapshot
278
+ // module and no `runtime.js` module exist.
279
+ ( snapshot ? [ ] : [ "./runtime" ] )
280
+ . concat ( [
281
+ "./vendor" ,
282
+ "./bundle" ,
283
+ ] )
284
+ ) ,
264
285
// For instructions on how to set up workers with webpack
265
286
// check out https://github.com/nativescript/worker-loader
266
287
new NativeScriptWorkerPlugin ( ) ,
@@ -270,6 +291,18 @@ module.exports = env => {
270
291
] ,
271
292
} ;
272
293
294
+ // Copy the native app resources to the out dir
295
+ // only if doing a full build (tns run/build) and not previewing (tns preview)
296
+ if ( ! externals || externals . length === 0 ) {
297
+ config . plugins . push ( new CopyWebpackPlugin ( [
298
+ {
299
+ from : `${ appResourcesFullPath } /${ appResourcesPlatformDir } ` ,
300
+ to : `${ dist } /App_Resources/${ appResourcesPlatformDir } ` ,
301
+ context : projectRoot
302
+ } ,
303
+ ] ) ) ;
304
+ }
305
+
273
306
274
307
if ( report ) {
275
308
// Generate report files for bundles content
0 commit comments