@@ -3,6 +3,7 @@ const { join, relative, resolve, sep } = require("path");
33const webpack = require ( "webpack" ) ;
44const nsWebpack = require ( "nativescript-dev-webpack" ) ;
55const nativescriptTarget = require ( "nativescript-dev-webpack/nativescript-target" ) ;
6+ const { getNoEmitOnErrorFromTSConfig } = require ( "nativescript-dev-webpack/utils/tsconfig-utils" ) ;
67const CleanWebpackPlugin = require ( "clean-webpack-plugin" ) ;
78const CopyWebpackPlugin = require ( "copy-webpack-plugin" ) ;
89const ForkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
@@ -13,26 +14,30 @@ const hashSalt = Date.now().toString();
1314
1415module . exports = env => {
1516 // Add your custom Activities, Services and other Android app components here.
16- const appComponents = [
17+ const appComponents = env . appComponents || [ ] ;
18+ appComponents . push ( ...[
1719 "tns-core-modules/ui/frame" ,
1820 "tns-core-modules/ui/frame/activity" ,
19- ] ;
21+ ] ) ;
2022
21- const platform = env && ( env . android && "android" || env . ios && "ios" ) ;
23+ const platform = env && ( env . android && "android" || env . ios && "ios" || env . platform ) ;
2224 if ( ! platform ) {
2325 throw new Error ( "You need to provide a target platform!" ) ;
2426 }
2527
2628 const platforms = [ "ios" , "android" ] ;
2729 const projectRoot = __dirname ;
2830
31+ if ( env . platform ) {
32+ platforms . push ( env . platform ) ;
33+ }
34+
2935 // Default destination inside platforms/<platform>/...
3036 const dist = resolve ( projectRoot , nsWebpack . getAppPath ( platform , projectRoot ) ) ;
3137
3238 const {
3339 // The 'appPath' and 'appResourcesPath' values are fetched from
34- // the nsconfig.json configuration file
35- // when bundling with `tns run android|ios --bundle`.
40+ // the nsconfig.json configuration file.
3641 appPath = "app" ,
3742 appResourcesPath = "app/App_Resources" ,
3843
@@ -46,16 +51,31 @@ module.exports = env => {
4651 hmr, // --env.hmr,
4752 unitTesting, // --env.unitTesting,
4853 verbose, // --env.verbose
54+ snapshotInDocker, // --env.snapshotInDocker
55+ skipSnapshotTools, // --env.skipSnapshotTools
56+ compileSnapshot // --env.compileSnapshot
4957 } = env ;
58+
59+ const useLibs = compileSnapshot ;
5060 const isAnySourceMapEnabled = ! ! sourceMap || ! ! hiddenSourceMap ;
5161 const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
5262
5363 const appFullPath = resolve ( projectRoot , appPath ) ;
64+ const hasRootLevelScopedModules = nsWebpack . hasRootLevelScopedModules ( { projectDir : projectRoot } ) ;
65+ let coreModulesPackageName = "tns-core-modules" ;
66+ const alias = env . alias || { } ;
67+ alias [ '~' ] = appFullPath ;
68+
69+ if ( hasRootLevelScopedModules ) {
70+ coreModulesPackageName = "@nativescript/core" ;
71+ alias [ "tns-core-modules" ] = coreModulesPackageName ;
72+ }
5473 const appResourcesFullPath = resolve ( projectRoot , appResourcesPath ) ;
5574
5675 const entryModule = nsWebpack . getEntryModule ( appFullPath , platform ) ;
5776 const entryPath = `.${ sep } ${ entryModule } .ts` ;
58- const entries = { bundle : entryPath } ;
77+ const entries = env . entries || { } ;
78+ entries . bundle = entryPath ;
5979
6080 const tsConfigPath = resolve ( projectRoot , "tsconfig.tns.json" ) ;
6181
@@ -72,6 +92,8 @@ module.exports = env => {
7292 itemsToClean . push ( `${ join ( projectRoot , "platforms" , "android" , "app" , "build" , "configurations" , "nativescript-android-snapshot" ) } ` ) ;
7393 }
7494
95+ const noEmitOnErrorFromTSConfig = getNoEmitOnErrorFromTSConfig ( tsConfigPath ) ;
96+
7597 nsWebpack . processAppComponents ( appComponents , platform ) ;
7698 const config = {
7799 mode : production ? "production" : "development" ,
@@ -99,14 +121,12 @@ module.exports = env => {
99121 extensions : [ ".ts" , ".js" , ".scss" , ".css" ] ,
100122 // Resolve {N} system modules from tns-core-modules
101123 modules : [
102- resolve ( __dirname , " node_modules/tns-core-modules" ) ,
124+ resolve ( __dirname , ` node_modules/${ coreModulesPackageName } ` ) ,
103125 resolve ( __dirname , "node_modules" ) ,
104- " node_modules/tns-core-modules" ,
126+ ` node_modules/${ coreModulesPackageName } ` ,
105127 "node_modules" ,
106128 ] ,
107- alias : {
108- '~' : appFullPath
109- } ,
129+ alias,
110130 // resolve symlinks to symlinked modules
111131 symlinks : true
112132 } ,
@@ -125,6 +145,7 @@ module.exports = env => {
125145 devtool : hiddenSourceMap ? "hidden-source-map" : ( sourceMap ? "inline-source-map" : "none" ) ,
126146 optimization : {
127147 runtimeChunk : "single" ,
148+ noEmitOnErrors : noEmitOnErrorFromTSConfig ,
128149 splitChunks : {
129150 cacheGroups : {
130151 vendor : {
@@ -164,7 +185,7 @@ module.exports = env => {
164185 module : {
165186 rules : [
166187 {
167- test : nsWebpack . getEntryPathRegExp ( appFullPath , entryPath ) ,
188+ include : join ( appFullPath , entryPath ) ,
168189 use : [
169190 // Require all Android app components
170191 platform === "android" && {
@@ -194,13 +215,13 @@ module.exports = env => {
194215
195216 {
196217 test : / \. c s s $ / ,
197- use : { loader : "css- loader", options : { url : false } }
218+ use : "nativescript-dev-webpack/css2json- loader"
198219 } ,
199220
200221 {
201222 test : / \. s c s s $ / ,
202223 use : [
203- { loader : "css- loader", options : { url : false } } ,
224+ "nativescript-dev-webpack/css2json- loader",
204225 "sass-loader"
205226 ]
206227 } ,
@@ -255,6 +276,7 @@ module.exports = env => {
255276 tsconfig : tsConfigPath ,
256277 async : false ,
257278 useTypescriptIncrementalApi : true ,
279+ checkSyntacticErrors : true ,
258280 memoryLimit : 4096
259281 } )
260282 ] ,
@@ -279,6 +301,9 @@ module.exports = env => {
279301 ] ,
280302 projectRoot,
281303 webpackConfig : config ,
304+ snapshotInDocker,
305+ skipSnapshotTools,
306+ useLibs
282307 } ) ) ;
283308 }
284309
0 commit comments