@@ -47,6 +47,7 @@ module.exports = env => {
47
47
report, // --env.report
48
48
sourceMap, // --env.sourceMap
49
49
hmr, // --env.hmr,
50
+ unitTesting, // --env.unitTesting
50
51
} = env ;
51
52
52
53
const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
@@ -55,6 +56,11 @@ module.exports = env => {
55
56
const tsConfigName = "tsconfig.tns.json" ;
56
57
const entryModule = `${ nsWebpack . getEntryModule ( appFullPath ) } .ts` ;
57
58
const entryPath = `.${ sep } ${ entryModule } ` ;
59
+ const entries = { bundle : entryPath } ;
60
+ if ( platform === "ios" ) {
61
+ entries [ "tns_modules/tns-core-modules/inspector_modules" ] = "inspector_modules.js" ;
62
+ } ;
63
+
58
64
const ngCompilerTransformers = [ ] ;
59
65
const additionalLazyModuleResources = [ ] ;
60
66
if ( aot ) {
@@ -101,9 +107,7 @@ module.exports = env => {
101
107
]
102
108
} ,
103
109
target : nativescriptTarget ,
104
- entry : {
105
- bundle : entryPath ,
106
- } ,
110
+ entry : entries ,
107
111
output : {
108
112
pathinfo : false ,
109
113
path : dist ,
@@ -139,6 +143,7 @@ module.exports = env => {
139
143
} ,
140
144
devtool : sourceMap ? "inline-source-map" : "none" ,
141
145
optimization : {
146
+ runtimeChunk : "single" ,
142
147
splitChunks : {
143
148
cacheGroups : {
144
149
vendor : {
@@ -175,7 +180,7 @@ module.exports = env => {
175
180
module : {
176
181
rules : [
177
182
{
178
- test : new RegExp ( entryPath ) ,
183
+ test : nsWebpack . getEntryPathRegExp ( appFullPath , entryPath ) ,
179
184
use : [
180
185
// Require all Android app components
181
186
platform === "android" && {
@@ -188,6 +193,9 @@ module.exports = env => {
188
193
options : {
189
194
angular : true ,
190
195
loadCss : ! snapshot , // load the application css if in debug mode
196
+ unitTesting,
197
+ appFullPath,
198
+ projectRoot,
191
199
}
192
200
} ,
193
201
] . filter ( loader => ! ! loader )
@@ -241,25 +249,23 @@ module.exports = env => {
241
249
} ) ,
242
250
// Remove all files from the out dir.
243
251
new CleanWebpackPlugin ( [ `${ dist } /**/*` ] ) ,
244
- // Copy native app resources to out dir.
245
- new CopyWebpackPlugin ( [
246
- {
247
- from : `${ appResourcesFullPath } /${ appResourcesPlatformDir } ` ,
248
- to : `${ dist } /App_Resources/${ appResourcesPlatformDir } ` ,
249
- context : projectRoot
250
- } ,
251
- ] ) ,
252
252
// Copy assets to out dir. Add your own globs as needed.
253
253
new CopyWebpackPlugin ( [
254
254
{ from : { glob : "fonts/**" } } ,
255
255
{ from : { glob : "**/*.jpg" } } ,
256
256
{ from : { glob : "**/*.png" } } ,
257
257
] , { ignore : [ `${ relative ( appPath , appResourcesFullPath ) } /**` ] } ) ,
258
258
// Generate a bundle starter script and activate it in package.json
259
- new nsWebpack . GenerateBundleStarterPlugin ( [
260
- "./vendor" ,
261
- "./bundle" ,
262
- ] ) ,
259
+ new nsWebpack . GenerateBundleStarterPlugin (
260
+ // Don't include `runtime.js` when creating a snapshot. The plugin
261
+ // configures the WebPack runtime to be generated inside the snapshot
262
+ // module and no `runtime.js` module exist.
263
+ ( snapshot ? [ ] : [ "./runtime" ] )
264
+ . concat ( [
265
+ "./vendor" ,
266
+ "./bundle" ,
267
+ ] )
268
+ ) ,
263
269
// For instructions on how to set up workers with webpack
264
270
// check out https://github.com/nativescript/worker-loader
265
271
new NativeScriptWorkerPlugin ( ) ,
@@ -269,6 +275,18 @@ module.exports = env => {
269
275
] ,
270
276
} ;
271
277
278
+ // Copy the native app resources to the out dir
279
+ // only if doing a full build (tns run/build) and not previewing (tns preview)
280
+ if ( ! externals || externals . length === 0 ) {
281
+ config . plugins . push ( new CopyWebpackPlugin ( [
282
+ {
283
+ from : `${ appResourcesFullPath } /${ appResourcesPlatformDir } ` ,
284
+ to : `${ dist } /App_Resources/${ appResourcesPlatformDir } ` ,
285
+ context : projectRoot
286
+ } ,
287
+ ] ) ) ;
288
+ }
289
+
272
290
273
291
if ( report ) {
274
292
// Generate report files for bundles content
0 commit comments