@@ -6,6 +6,7 @@ const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target
6
6
const CleanWebpackPlugin = require ( "clean-webpack-plugin" ) ;
7
7
const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
8
8
const ForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
9
+ const ExtraWatchWebpackPlugin = require ( 'extra-watch-webpack-plugin' ) ;
9
10
const { BundleAnalyzerPlugin } = require ( "webpack-bundle-analyzer" ) ;
10
11
const { NativeScriptWorkerPlugin } = require ( "nativescript-worker-loader/NativeScriptWorkerPlugin" ) ;
11
12
const TerserPlugin = require ( "terser-webpack-plugin" ) ;
@@ -40,12 +41,14 @@ module.exports = env => {
40
41
41
42
// You can provide the following flags when running 'tns run android|ios'
42
43
snapshot, // --env.snapshot
44
+ production, // --env.production
43
45
uglify, // --env.uglify
44
46
report, // --env.report
45
47
sourceMap, // --env.sourceMap
46
48
hiddenSourceMap, // --env.hiddenSourceMap
47
49
hmr, // --env.hmr,
48
- unitTesting, // --env.unitTesting
50
+ unitTesting, // --env.unitTesting,
51
+ verbose, // --env.verbose
49
52
} = env ;
50
53
const isAnySourceMapEnabled = ! ! sourceMap || ! ! hiddenSourceMap ;
51
54
const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
@@ -59,14 +62,21 @@ module.exports = env => {
59
62
60
63
const tsConfigPath = resolve ( projectRoot , "tsconfig.tns.json" ) ;
61
64
62
- if ( platform === "ios" ) {
65
+ const areCoreModulesExternal = Array . isArray ( env . externals ) && env . externals . some ( e => e . indexOf ( "tns-core-modules" ) > - 1 ) ;
66
+ if ( platform === "ios" && ! areCoreModulesExternal ) {
63
67
entries [ "tns_modules/tns-core-modules/inspector_modules" ] = "inspector_modules" ;
64
68
} ;
65
69
66
70
let sourceMapFilename = nsWebpack . getSourceMapFilename ( hiddenSourceMap , __dirname , dist ) ;
67
71
72
+ const itemsToClean = [ `${ dist } /**/*` ] ;
73
+ if ( platform === "android" ) {
74
+ itemsToClean . push ( `${ join ( projectRoot , "platforms" , "android" , "app" , "src" , "main" , "assets" , "snapshots" ) } ` ) ;
75
+ itemsToClean . push ( `${ join ( projectRoot , "platforms" , "android" , "app" , "build" , "configurations" , "nativescript-android-snapshot" ) } ` ) ;
76
+ }
77
+
68
78
const config = {
69
- mode : uglify ? "production" : "development" ,
79
+ mode : production ? "production" : "development" ,
70
80
context : appFullPath ,
71
81
externals,
72
82
watchOptions : {
@@ -212,10 +222,13 @@ module.exports = env => {
212
222
loader : "ts-loader" ,
213
223
options : {
214
224
configFile : tsConfigPath ,
215
- transpileOnly : ! ! hmr ,
225
+ // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
226
+ // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
227
+ transpileOnly : true ,
216
228
allowTsInNodeModules : true ,
217
229
compilerOptions : {
218
- sourceMap : isAnySourceMapEnabled
230
+ sourceMap : isAnySourceMapEnabled ,
231
+ declaration : false
219
232
}
220
233
} ,
221
234
}
@@ -229,7 +242,7 @@ module.exports = env => {
229
242
"process" : undefined ,
230
243
} ) ,
231
244
// Remove all files from the out dir.
232
- new CleanWebpackPlugin ( [ ` ${ dist } /**/*` ] ) ,
245
+ new CleanWebpackPlugin ( itemsToClean , { verbose : ! ! verbose } ) ,
233
246
// Copy assets to out dir. Add your own globs as needed.
234
247
new CopyWebpackPlugin ( [
235
248
{ from : { glob : "fonts/**" } } ,
@@ -246,21 +259,20 @@ module.exports = env => {
246
259
} ) ,
247
260
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
248
261
new nsWebpack . WatchStateLoggerPlugin ( ) ,
262
+ // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#faster-builds
263
+ // https://github.com/TypeStrong/ts-loader/blob/ea2fcf925ec158d0a536d1e766adfec6567f5fb4/README.md#hot-module-replacement
264
+ new ForkTsCheckerWebpackPlugin ( {
265
+ tsconfig : tsConfigPath ,
266
+ async : false ,
267
+ useTypescriptIncrementalApi : true ,
268
+ memoryLimit : 4096
269
+ } ) ,
270
+ new ExtraWatchWebpackPlugin ( {
271
+ files : [ `node_modules/**/*.${ platform } .ts` ]
272
+ } )
249
273
] ,
250
274
} ;
251
275
252
- // Copy the native app resources to the out dir
253
- // only if doing a full build (tns run/build) and not previewing (tns preview)
254
- if ( ! externals || externals . length === 0 ) {
255
- config . plugins . push ( new CopyWebpackPlugin ( [
256
- {
257
- from : `${ appResourcesFullPath } /${ appResourcesPlatformDir } ` ,
258
- to : `${ dist } /App_Resources/${ appResourcesPlatformDir } ` ,
259
- context : projectRoot
260
- } ,
261
- ] ) ) ;
262
- }
263
-
264
276
if ( report ) {
265
277
// Generate report files for bundles content
266
278
config . plugins . push ( new BundleAnalyzerPlugin ( {
@@ -285,12 +297,6 @@ module.exports = env => {
285
297
286
298
if ( hmr ) {
287
299
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
- } ) ) ;
294
300
}
295
301
296
302
0 commit comments