@@ -6,8 +6,6 @@ const fs = require('fs-extra');
6
6
const webpack = require ( 'webpack' ) ;
7
7
const CleanWebpackPlugin = require ( 'clean-webpack-plugin' ) ;
8
8
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
9
- const DefinePlugin = require ( 'webpack/lib/DefinePlugin' ) ;
10
-
11
9
const { BundleAnalyzerPlugin } = require ( 'webpack-bundle-analyzer' ) ;
12
10
const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
13
11
@@ -20,10 +18,13 @@ const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeS
20
18
21
19
const hashSalt = Date . now ( ) . toString ( ) ;
22
20
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;
27
28
28
29
const resolveExtensionsOptions = {
29
30
web : [ '*' , '.ts' , '.tsx' , '.js' , '.jsx' , '.vue' , '.json' , '.scss' , '.styl' , '.less' , '.css' ] ,
@@ -81,6 +82,8 @@ const resolveExtensionsOptions = {
81
82
82
83
const getBlockRegex = ( tag , mode ) => {
83
84
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}>))`;
84
87
} ;
85
88
86
89
module . exports = ( api , projectOptions ) => {
@@ -119,10 +122,7 @@ module.exports = (api, projectOptions) => {
119
122
// console.log('platform - ', platform);
120
123
121
124
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!' ) ;
126
126
}
127
127
128
128
const projectRoot = api . service . context ;
@@ -166,37 +166,51 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
166
166
hmr, // --env.hmr
167
167
sourceMap, // -env.sourceMap
168
168
hiddenSourceMap, // -env.HiddenSourceMap
169
- unitTesting // -env.unittesting
169
+ unitTesting, // -env.unittesting
170
+ verbose // --env.verbose
170
171
} = env ;
171
172
172
173
const isAnySourceMapEnabled = ! ! sourceMap || ! ! hiddenSourceMap ;
174
+ const externals = nsWebpack . getConvertedExternals ( env . externals ) ;
173
175
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
+ // / / // });
178
180
179
181
const mode = production ? 'production' : 'development' ;
180
182
181
183
const appFullPath = resolve ( projectRoot , appPath ) ;
182
184
const appResourcesFullPath = resolve ( projectRoot , appResourcesPath ) ;
183
185
184
- const entryModule = nsWebpack . getEntryModule ( appFullPath ) ;
186
+ // const entryModule = nsWebpack.getEntryModule(appFullPath);
187
+ const entryModule = nsWebpack . getEntryModule ( appFullPath , platform ) ;
185
188
const entryPath = `.${ sep } ${ entryModule } ` ;
186
189
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' ;
189
196
}
190
197
191
198
console . log ( `Bundling application for entryPath ${ entryPath } ...` ) ;
192
199
193
200
let sourceMapFilename = nsWebpack . getSourceMapFilename ( hiddenSourceMap , __dirname , dist ) ;
194
201
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
+
195
210
api . chainWebpack ( ( config ) => {
196
211
config
197
212
. mode ( mode )
198
213
. context ( appFullPath )
199
- // .devtool('none') --> OLD WILL SOON BE DELETED
200
214
. devtool ( hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none' )
201
215
. end ( ) ;
202
216
@@ -272,6 +286,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
272
286
. set ( 'styles' , resolve ( isNativeOnly ? api . resolve ( 'app' ) : api . resolve ( 'src' ) , 'styles' ) )
273
287
. set ( 'root' , projectRoot )
274
288
. set ( 'vue$' , 'nativescript-vue' )
289
+ . set ( 'vue' , 'nativescript-vue' )
275
290
. end ( )
276
291
. symlinks ( true ) // don't resolve symlinks to symlinked modules
277
292
. end ( ) ;
@@ -340,7 +355,8 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
340
355
loadCss : ! snapshot , // load the application css if in debug mode
341
356
unitTesting,
342
357
appFullPath,
343
- projectRoot
358
+ projectRoot,
359
+ ignoredFiles : nsWebpack . getUserDefinedEntries ( entries , platform )
344
360
} )
345
361
. end ( ) ;
346
362
@@ -433,6 +449,12 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
433
449
434
450
tsConfigOptions . configFile = resolve ( projectRoot , tsconfigFileName ) ;
435
451
452
+ ( tsConfigOptions . appendTsSuffixTo = [ / \. v u e $ / ] ) ,
453
+ ( tsConfigOptions . allowTsInNodeModules = true ) ,
454
+ ( tsConfigOptions . compilerOptions = {
455
+ declaration : false
456
+ } ) ;
457
+
436
458
config . module
437
459
. rule ( 'ts' )
438
460
. test ( / \. t s $ / )
@@ -451,6 +473,11 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
451
473
. get ( 'options' ) ;
452
474
453
475
tsxConfigOptions . configFile = resolve ( projectRoot , tsconfigFileName ) ;
476
+ ( tsxConfigOptions . appendTsSuffixTo = [ / \. v u e $ / ] ) ,
477
+ ( tsxConfigOptions . allowTsInNodeModules = true ) ,
478
+ ( tsxConfigOptions . compilerOptions = {
479
+ declaration : false
480
+ } ) ;
454
481
455
482
config . module
456
483
. rule ( 'tsx' )
@@ -498,7 +525,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
498
525
. uses . get ( 'css-loader' )
499
526
. get ( 'options' ) ,
500
527
{
501
- minimize : false ,
528
+ // minimize: false,
502
529
url : false ,
503
530
importLoaders : 1
504
531
}
@@ -560,7 +587,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
560
587
. uses . get ( 'sass-loader' )
561
588
. get ( 'options' ) ,
562
589
{
563
- minimize : false ,
590
+ // minimize: false,
564
591
url : false ,
565
592
data : '$PLATFORM: ' + platform + ';'
566
593
}
@@ -605,7 +632,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
605
632
. uses . get ( 'css-loader' )
606
633
. get ( 'options' ) ,
607
634
{
608
- minimize : false ,
635
+ // minimize: false,
609
636
url : false ,
610
637
data : '$PLATFORM: ' + platform
611
638
}
@@ -663,7 +690,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
663
690
. uses . get ( 'css-loader' )
664
691
. get ( 'options' ) ,
665
692
{
666
- minimize : false ,
693
+ // minimize: false,
667
694
url : false
668
695
}
669
696
)
@@ -719,7 +746,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
719
746
. uses . get ( 'css-loader' )
720
747
. get ( 'options' ) ,
721
748
{
722
- minimize : false ,
749
+ // minimize: false,
723
750
url : false
724
751
}
725
752
)
@@ -735,7 +762,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
735
762
. uses . get ( 'less-loader' )
736
763
. get ( 'options' ) ,
737
764
{
738
- minimize : false ,
765
+ // minimize: false,
739
766
url : false
740
767
}
741
768
)
@@ -762,12 +789,6 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
762
789
// delete these rules that come standard with CLI 3
763
790
// need to look at adding these back in after evaluating impact
764
791
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
771
792
772
793
// only delete the plugin if we aren't calling for HMR
773
794
if ( ! env . hmr ) {
@@ -804,7 +825,9 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
804
825
. plugin ( 'define' )
805
826
. use ( DefinePlugin , [
806
827
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'
808
831
} )
809
832
] )
810
833
. end ( ) ;
@@ -813,10 +836,12 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
813
836
config
814
837
. plugin ( 'clean' )
815
838
. use ( CleanWebpackPlugin , [
816
- join ( dist , '/**/*' ) ,
817
- {
818
- root : dist
819
- }
839
+ itemsToClean ,
840
+ { verbose : ! ! verbose }
841
+ // join(dist, '/**/*'),
842
+ // {
843
+ // root: dist
844
+ // }
820
845
] )
821
846
. end ( ) ;
822
847
@@ -887,7 +912,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
887
912
888
913
config
889
914
. plugin ( 'platform-FS' )
890
- . use ( PlatformFSPlugin , [
915
+ . use ( nsWebpack . PlatformFSPlugin , [
891
916
{
892
917
platform,
893
918
platforms
@@ -898,7 +923,7 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
898
923
// Does IPC communication with the {N} CLI to notify events when running in watch mode.
899
924
config
900
925
. plugin ( 'watch-state-logger' )
901
- . use ( WatchStateLoggerPlugin , [ ] )
926
+ . use ( nsWebpack . WatchStateLoggerPlugin , [ ] )
902
927
. end ( ) ;
903
928
904
929
// Another only do this if we're using typescript. this code could have been put
0 commit comments