Skip to content

Commit fc3a9f3

Browse files
author
Gary Gambill
committed
Updated to NS 6 & 6.1
1 parent 1695bd9 commit fc3a9f3

File tree

4 files changed

+1451
-838
lines changed

4 files changed

+1451
-838
lines changed

Diff for: generator/index.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,39 @@ module.exports = async (api, options, rootOptions) => {
5454
nativescript: {
5555
id: 'org.nativescript.application',
5656
'tns-ios': {
57-
version: '5.4.0'
57+
version: '6.1.0'
5858
},
5959
'tns-android': {
60-
version: '5.4.0'
60+
version: '6.1.0'
6161
}
6262
},
6363
scripts: {
64-
'build:android': 'npm run setup-webpack-config && tns build android --bundle --env.production && npm run remove-webpack-config',
65-
'build:ios': 'npm run setup-webpack-config && tns build ios --bundle --env.production && npm run remove-webpack-config',
64+
'build:android': 'npm run setup-webpack-config && tns build android --env.production && npm run remove-webpack-config',
65+
'build:ios': 'npm run setup-webpack-config && tns build ios --env.production && npm run remove-webpack-config',
6666
'remove-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance post',
67-
'serve:android': 'npm run setup-webpack-config && tns run android --bundle --env.development',
68-
'serve:ios': 'npm run setup-webpack-config && tns run ios --bundle --env.development',
67+
'serve:android': 'npm run setup-webpack-config && tns run android --env.development',
68+
'serve:ios': 'npm run setup-webpack-config && tns run ios --env.development',
6969
// 'inspect:android': 'npm run setup-webpack-config && vue inspect -- --env.android > out-android.js',
7070
// 'inspect:ios': 'npm run setup-webpack-config && vue inspect -- --env.ios > out-ios.js',
71-
'debug:android': 'npm run setup-webpack-config && tns debug android --bundle --env.development',
72-
'debug:ios': 'npm run setup-webpack-config && tns debug ios --bundle --env.development',
73-
'preview:android': 'npm run setup-webpack-config && tns preview --bundle --env.development --env.android',
74-
'preview:ios': 'npm run setup-webpack-config && tns preview --bundle --env.development --env.ios',
71+
'debug:android': 'npm run setup-webpack-config && tns debug android --env.development',
72+
'debug:ios': 'npm run setup-webpack-config && tns debug ios --env.development',
73+
'preview:android': 'npm run setup-webpack-config && tns preview --env.development --env.android',
74+
'preview:ios': 'npm run setup-webpack-config && tns preview --env.development --env.ios',
7575
'setup-webpack-config': 'node ./node_modules/vue-cli-plugin-nativescript-vue/lib/scripts/webpack-maintenance pre',
7676
'clean:platforms': 'rimraf platforms',
7777
'clean:android': 'rimraf platforms/android',
7878
'clean:ios': 'rimraf platforms/ios'
7979
},
8080
dependencies: {
81-
'nativescript-vue': '^2.2.2',
82-
'tns-core-modules': '^5.4.1'
81+
'nativescript-vue': '^2.4.0',
82+
'tns-core-modules': '^6.1.0'
8383
},
8484
devDependencies: {
85-
'nativescript-dev-webpack': '^0.24.0',
86-
'nativescript-vue-template-compiler': '^2.2.2',
85+
'nativescript-dev-webpack': '^1.2.0',
86+
'nativescript-vue-template-compiler': '^2.4.0',
8787
'nativescript-worker-loader': '~0.9.5',
88-
'node-sass': '^4.11.0',
89-
'string-replace-loader': '^2.1.1',
88+
'node-sass': '^4.12.0',
89+
'string-replace-loader': '^2.2.0',
9090
rimraf: '^2.6.3'
9191
// webpack: '4.28.4',
9292
// 'webpack-cli': '^3.3.2'
@@ -118,7 +118,7 @@ module.exports = async (api, options, rootOptions) => {
118118
if (rootOptions.router) {
119119
api.extendPackage({
120120
dependencies: {
121-
'nativescript-vue-navigator': '^0.0.3'
121+
'nativescript-vue-navigator': '^0.2.0'
122122
}
123123
});
124124
}
@@ -127,9 +127,9 @@ module.exports = async (api, options, rootOptions) => {
127127
api.extendPackage({
128128
dependencies: {},
129129
devDependencies: {
130-
'fork-ts-checker-webpack-plugin': '^1.3.4',
131-
'terser-webpack-plugin': '^1.3.0'
132-
//'tns-platform-declarations': '^4.2.1'
130+
'fork-ts-checker-webpack-plugin': '^1.5.0',
131+
'terser-webpack-plugin': '^2.0.1',
132+
'tns-platform-declarations': '^6.1.0'
133133
}
134134
});
135135

@@ -148,10 +148,10 @@ module.exports = async (api, options, rootOptions) => {
148148
if (api.hasPlugin('babel')) {
149149
api.extendPackage({
150150
devDependencies: {
151-
'@babel/core': '^7.4.5',
152-
'@babel/preset-env': '^7.4.5',
151+
'@babel/core': '^7.5.5',
152+
'@babel/preset-env': '^7.5.5',
153153
'babel-loader': '^8.0.6',
154-
'@babel/traverse': '^7.4.5'
154+
'@babel/traverse': '^7.5.5'
155155
}
156156
});
157157

Diff for: index.js

+64-39
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const fs = require('fs-extra');
66
const webpack = require('webpack');
77
const CleanWebpackPlugin = require('clean-webpack-plugin');
88
const CopyWebpackPlugin = require('copy-webpack-plugin');
9-
const DefinePlugin = require('webpack/lib/DefinePlugin');
10-
119
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
1210
const TerserPlugin = require('terser-webpack-plugin');
1311

@@ -20,10 +18,13 @@ const { NativeScriptWorkerPlugin } = require('nativescript-worker-loader/NativeS
2018

2119
const 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

2829
const resolveExtensionsOptions = {
2930
web: ['*', '.ts', '.tsx', '.js', '.jsx', '.vue', '.json', '.scss', '.styl', '.less', '.css'],
@@ -81,6 +82,8 @@ const resolveExtensionsOptions = {
8182

8283
const 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

8689
module.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 = [/\.vue$/]),
453+
(tsConfigOptions.allowTsInNodeModules = true),
454+
(tsConfigOptions.compilerOptions = {
455+
declaration: false
456+
});
457+
436458
config.module
437459
.rule('ts')
438460
.test(/\.ts$/)
@@ -451,6 +473,11 @@ const nativeConfig = (api, projectOptions, env, projectRoot, platform) => {
451473
.get('options');
452474

453475
tsxConfigOptions.configFile = resolve(projectRoot, tsconfigFileName);
476+
(tsxConfigOptions.appendTsSuffixTo = [/\.vue$/]),
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

Comments
 (0)