@@ -6,8 +6,6 @@ const fs = require('fs-extra');
66const webpack = require ( 'webpack' ) ;
77const CleanWebpackPlugin = require ( 'clean-webpack-plugin' ) ;
88const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
9- const DefinePlugin = require ( 'webpack/lib/DefinePlugin' ) ;
10-
119const { BundleAnalyzerPlugin } = require ( 'webpack-bundle-analyzer' ) ;
1210const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
1311
@@ -20,10 +18,13 @@ const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeS
2018
2119const hashSalt = Date . now ( ) . toString ( ) ;
2220
23- // eslint-disable-next-line prefer-destructuring
24- const PlatformFSPlugin = nsWebpack . PlatformFSPlugin ;
25- // eslint-disable-next-line prefer-destructuring
26- const WatchStateLoggerPlugin = nsWebpack . WatchStateLoggerPlugin ;
21+ const DefinePlugin = require ( 'webpack/lib/DefinePlugin' ) ;
22+
23+ // // // TO BE REMOVED SOON
24+ // // // // eslint-disable-next-line prefer-destructuring
25+ // // // const PlatformFSPlugin = nsWebpack.PlatformFSPlugin;
26+ // // // // eslint-disable-next-line prefer-destructuring
27+ // // // const WatchStateLoggerPlugin = nsWebpack.WatchStateLoggerPlugin;
2728
2829const resolveExtensionsOptions = {
2930 web : [ '*' , '.ts' , '.tsx' , '.js' , '.jsx' , '.vue' , '.json' , '.scss' , '.styl' , '.less' , '.css' ] ,
@@ -81,6 +82,8 @@ const resolveExtensionsOptions = {
8182
8283const getBlockRegex = ( tag , mode ) => {
8384 return `^((<${ tag } )(.+\\b${ mode } \\b))([\\s\\S]*?>)[\\s\\S]*?(<\\/${ tag } >)` ;
85+ // Rejected code from PR #26 as the issue could not be reproduced. Leaving it in commented out in case we need to look at this again in the future.
86+ // return `^((<${tag})(.+\\b${mode}\\b))([\\s\\S]*?>)((?=[\\s\\S]*?<${tag}.+\\b${mode === 'web' ? 'native' : 'web'}\\b[\\s\\S]*?>)([\\s\\S]+(?=[\\s\\S]*?<${tag}.+\\b${mode === 'web' ? 'native' : 'web'}\\b[\\s\\S]*?>))|([\\s\\S]+<\\/${tag}>))`;
8487} ;
8588
8689module . exports = ( api , projectOptions ) => {
@@ -119,10 +122,7 @@ module.exports = (api, projectOptions) => {
119122 // console.log('platform - ', platform);
120123
121124 if ( ! platform ) {
122- // TNS (iOS/Android) always sets platform, so assume platform = 'web' & Vue-CLI glitch of loosing .env options in the UI
123- platform = 'web' ;
124- // --> TO BE DELETED SOON
125- // throw new Error('You need to provide a target platform!');
125+ throw new Error ( 'You need to provide a target platform!' ) ;
126126 }
127127
128128 const projectRoot = api . service . context ;
@@ -166,37 +166,51 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
166166 hmr, // --env.hmr
167167 sourceMap, // -env.sourceMap
168168 hiddenSourceMap, // -env.HiddenSourceMap
169- unitTesting // -env.unittesting
169+ unitTesting, // -env.unittesting
170+ verbose // --env.verbose
170171 } = env ;
171172
172173 const isAnySourceMapEnabled = ! ! sourceMap || ! ! hiddenSourceMap ;
174+ const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
173175
174- // --env.externals
175- const externals = ( env . externals || [ ] ) . map ( ( e ) => {
176- return new RegExp ( e + '.*' ) ;
177- } ) ;
176+ // // // // --env.externals
177+ // // // const externals = (env.externals || []).map((e) => {
178+ // // // return new RegExp(e + '.*');
179+ // / / // });
178180
179181 const mode = production ? 'production' : 'development' ;
180182
181183 const appFullPath = resolve ( projectRoot , appPath ) ;
182184 const appResourcesFullPath = resolve ( projectRoot , appResourcesPath ) ;
183185
184- const entryModule = nsWebpack . getEntryModule ( appFullPath ) ;
186+ // const entryModule = nsWebpack.getEntryModule(appFullPath);
187+ const entryModule = nsWebpack . getEntryModule ( appFullPath , platform ) ;
185188 const entryPath = `.${ sep } ${ entryModule } ` ;
186189 const entries = { bundle : entryPath } ;
187- if ( platform === 'ios' ) {
188- entries [ 'tns_modules/tns-core-modules/inspector_modules' ] = 'inspector_modules.js' ;
190+ const areCoreModulesExternal = Array . isArray ( env . externals ) && env . externals . some ( ( e ) => e . indexOf ( 'tns-core-modules' ) > - 1 ) ;
191+ // // if (platform === 'ios' ) {
192+ // // entries['tns_modules/tns-core-modules/inspector_modules'] = 'inspector_modules.js';
193+ // // }
194+ if ( platform === 'ios' && ! areCoreModulesExternal ) {
195+ entries [ 'tns_modules/tns-core-modules/inspector_modules' ] = 'inspector_modules' ;
189196 }
190197
191198 console . log ( `Bundling application for entryPath ${ entryPath } ...` ) ;
192199
193200 let sourceMapFilename = nsWebpack . getSourceMapFilename ( hiddenSourceMap , __dirname , dist ) ;
194201
202+ const itemsToClean = [ `${ dist } /**/*` ] ;
203+ if ( platform === 'android' ) {
204+ itemsToClean . push ( `${ join ( projectRoot , 'platforms' , 'android' , 'app' , 'src' , 'main' , 'assets' , 'snapshots' ) } ` ) ;
205+ itemsToClean . push ( `${ join ( projectRoot , 'platforms' , 'android' , 'app' , 'build' , 'configurations' , 'nativescript-android-snapshot' ) } ` ) ;
206+ }
207+
208+ nsWebpack . processAppComponents ( appComponents , platform ) ;
209+
195210 api . chainWebpack ( ( config ) => {
196211 config
197212 . mode ( mode )
198213 . context ( appFullPath )
199- // .devtool('none') --> OLD WILL SOON BE DELETED
200214 . devtool ( hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none' )
201215 . end ( ) ;
202216
@@ -272,6 +286,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
272286 . set ( 'styles' , resolve ( isNativeOnly ? api . resolve ( 'app' ) : api . resolve ( 'src' ) , 'styles' ) )
273287 . set ( 'root' , projectRoot )
274288 . set ( 'vue$' , 'nativescript-vue' )
289+ . set ( 'vue' , 'nativescript-vue' )
275290 . end ( )
276291 . symlinks ( true ) // don't resolve symlinks to symlinked modules
277292 . end ( ) ;
@@ -340,7 +355,8 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
340355 loadCss : ! snapshot , // load the application css if in debug mode
341356 unitTesting,
342357 appFullPath,
343- projectRoot
358+ projectRoot,
359+ ignoredFiles : nsWebpack . getUserDefinedEntries ( entries , platform )
344360 } )
345361 . end ( ) ;
346362
@@ -433,6 +449,12 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
433449
434450 tsConfigOptions . configFile = resolve ( projectRoot , tsconfigFileName ) ;
435451
452+ ( tsConfigOptions . appendTsSuffixTo = [ / \. v u e $ / ] ) ,
453+ ( tsConfigOptions . allowTsInNodeModules = true ) ,
454+ ( tsConfigOptions . compilerOptions = {
455+ declaration : false
456+ } ) ;
457+
436458 config . module
437459 . rule ( 'ts' )
438460 . test ( / \. t s $ / )
@@ -451,6 +473,11 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
451473 . get ( 'options' ) ;
452474
453475 tsxConfigOptions . configFile = resolve ( projectRoot , tsconfigFileName ) ;
476+ ( tsxConfigOptions . appendTsSuffixTo = [ / \. v u e $ / ] ) ,
477+ ( tsxConfigOptions . allowTsInNodeModules = true ) ,
478+ ( tsxConfigOptions . compilerOptions = {
479+ declaration : false
480+ } ) ;
454481
455482 config . module
456483 . rule ( 'tsx' )
@@ -498,7 +525,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
498525 . uses . get ( 'css-loader' )
499526 . get ( 'options' ) ,
500527 {
501- minimize : false ,
528+ // minimize: false,
502529 url : false ,
503530 importLoaders : 1
504531 }
@@ -560,7 +587,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
560587 . uses . get ( 'sass-loader' )
561588 . get ( 'options' ) ,
562589 {
563- minimize : false ,
590+ // minimize: false,
564591 url : false ,
565592 data : '$PLATFORM: ' + platform + ';'
566593 }
@@ -605,7 +632,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
605632 . uses . get ( 'css-loader' )
606633 . get ( 'options' ) ,
607634 {
608- minimize : false ,
635+ // minimize: false,
609636 url : false ,
610637 data : '$PLATFORM: ' + platform
611638 }
@@ -663,7 +690,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
663690 . uses . get ( 'css-loader' )
664691 . get ( 'options' ) ,
665692 {
666- minimize : false ,
693+ // minimize: false,
667694 url : false
668695 }
669696 )
@@ -719,7 +746,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
719746 . uses . get ( 'css-loader' )
720747 . get ( 'options' ) ,
721748 {
722- minimize : false ,
749+ // minimize: false,
723750 url : false
724751 }
725752 )
@@ -735,7 +762,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
735762 . uses . get ( 'less-loader' )
736763 . get ( 'options' ) ,
737764 {
738- minimize : false ,
765+ // minimize: false,
739766 url : false
740767 }
741768 )
@@ -762,12 +789,6 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
762789 // delete these rules that come standard with CLI 3
763790 // need to look at adding these back in after evaluating impact
764791 config . module . rules . delete ( 'images' ) . end ( ) ;
765- // config.module.rules.delete('svg'); --> TO BE DELETED SOON
766- // config.module.rules.delete('media'); --> TO BE DELETED SOON
767- // config.module.rules.delete('fonts'); --> TO BE DELETED SOON
768- // config.module.rules.delete('pug'); --> TO BE DELETED SOON
769- // config.module.rules.delete('postcss'); --> TO BE DELETED SOON
770- // config.module.rules.delete('eslint').end(); --> TO BE DELETED SOON
771792
772793 // only delete the plugin if we aren't calling for HMR
773794 if ( ! env . hmr ) {
@@ -804,7 +825,9 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
804825 . plugin ( 'define' )
805826 . use ( DefinePlugin , [
806827 Object . assign ( config . plugin ( 'define' ) . get ( 'args' ) [ 0 ] , {
807- TNS_ENV : JSON . stringify ( mode )
828+ 'global.TNS_WEBPACK' : 'true' ,
829+ TNS_ENV : JSON . stringify ( mode ) ,
830+ process : 'global.process'
808831 } )
809832 ] )
810833 . end ( ) ;
@@ -813,10 +836,12 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
813836 config
814837 . plugin ( 'clean' )
815838 . use ( CleanWebpackPlugin , [
816- join ( dist , '/**/*' ) ,
817- {
818- root : dist
819- }
839+ itemsToClean ,
840+ { verbose : ! ! verbose }
841+ // join(dist, '/**/*'),
842+ // {
843+ // root: dist
844+ // }
820845 ] )
821846 . end ( ) ;
822847
@@ -887,7 +912,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
887912
888913 config
889914 . plugin ( 'platform-FS' )
890- . use ( PlatformFSPlugin , [
915+ . use ( nsWebpack . PlatformFSPlugin , [
891916 {
892917 platform,
893918 platforms
@@ -898,7 +923,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
898923 // Does IPC communication with the {N} CLI to notify events when running in watch mode.
899924 config
900925 . plugin ( 'watch-state-logger' )
901- . use ( WatchStateLoggerPlugin , [ ] )
926+ . use ( nsWebpack . WatchStateLoggerPlugin , [ ] )
902927 . end ( ) ;
903928
904929 // Another only do this if we're using typescript. this code could have been put
0 commit comments