From 6a23baee25b3050b452f3ea84e60747451ba9fad Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Thu, 26 Apr 2018 17:30:17 +0300 Subject: [PATCH 1/2] feat(configs): move all node modules and android components to the common chunk --- templates/webpack.angular.js | 19 ++++++++++++------- templates/webpack.javascript.js | 19 ++++++++++++------- templates/webpack.typescript.js | 19 ++++++++++++------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 0e2a1b87..87f52ec4 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); module.exports = env => { + // Add your custom Activities, Services and other Android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + const platform = env && (env.android && "android" || env.ios && "ios"); if (!platform) { throw new Error("You need to provide a target platform!"); @@ -104,7 +110,12 @@ module.exports = env => { common: { name: "common", chunks: "all", - test: /vendor/, + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, enforce: true, }, } @@ -199,12 +210,6 @@ module.exports = env => { }; if (platform === "android") { - // Add your custom Activities, Services and other android app components here. - const appComponents = [ - "tns-core-modules/ui/frame", - "tns-core-modules/ui/frame/activity", - ]; - // Require all Android app components // in the entry module (bundle.ts) and the vendor module (vendor.ts). config.module.rules.unshift({ diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 75ee94f3..e7bdc4e4 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); module.exports = env => { + // Add your custom Activities, Services and other android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + const platform = env && (env.android && "android" || env.ios && "ios"); if (!platform) { throw new Error("You need to provide a target platform!"); @@ -100,7 +106,12 @@ module.exports = env => { common: { name: "common", chunks: "all", - test: /vendor/, + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, enforce: true, }, } @@ -173,12 +184,6 @@ module.exports = env => { }; if (platform === "android") { - // Add your custom Activities, Services and other android app components here. - const appComponents = [ - "tns-core-modules/ui/frame", - "tns-core-modules/ui/frame/activity", - ]; - // Require all Android app components // in the entry module (bundle.js) and the vendor module (vendor.js). config.module.rules.unshift({ diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index dfedb7de..a1dffcb3 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -10,6 +10,12 @@ const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeS const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); module.exports = env => { + // Add your custom Activities, Services and other Android app components here. + const appComponents = [ + "tns-core-modules/ui/frame", + "tns-core-modules/ui/frame/activity", + ]; + const platform = env && (env.android && "android" || env.ios && "ios"); if (!platform) { throw new Error("You need to provide a target platform!"); @@ -100,7 +106,12 @@ module.exports = env => { common: { name: "common", chunks: "all", - test: /vendor/, + test: (module, chunks) => { + const moduleName = module.nameForCondition ? module.nameForCondition() : ''; + return /[\\/]node_modules[\\/]/.test(moduleName) || + appComponents.some(comp => comp === moduleName); + + }, enforce: true, }, } @@ -175,12 +186,6 @@ module.exports = env => { }; if (platform === "android") { - // Add your custom Activities, Services and other android app components here. - const appComponents = [ - "tns-core-modules/ui/frame", - "tns-core-modules/ui/frame/activity", - ]; - // Require all Android app components // in the entry module (bundle.ts) and the vendor module (vendor.ts). config.module.rules.unshift({ From 35c9333ffd3a3edf83fecb95cc0bd655ee930bfc Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Thu, 26 Apr 2018 17:39:57 +0300 Subject: [PATCH 2/2] feat(configs): pass 'production' mode through the env object --- templates/webpack.angular.js | 15 +++++++-------- templates/webpack.javascript.js | 13 ++++++------- templates/webpack.typescript.js | 13 ++++++------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 87f52ec4..397281f4 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -36,13 +36,12 @@ module.exports = env => { appPath = "app", appResourcesPath = "app/App_Resources", - // Aot, snapshot, uglify and report can be enabled by providing - // the `--env.snapshot`, `--env.uglify` or `--env.report` flags - // when running 'tns run android|ios' - aot, - snapshot, - uglify, - report, + // You can provide the following flags when running 'tns run android|ios' + production, // --env.production + aot, // --env.aot + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report } = env; const ngToolsWebpackOptions = { tsConfigPath: join(__dirname, "tsconfig.json") }; @@ -56,7 +55,7 @@ module.exports = env => { const vendorPath = `.${sep}vendor.ts`; const config = { - mode: "development", + mode: production ? "production" : "development", context: appFullPath, watchOptions: { ignored: [ diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index e7bdc4e4..0f5b612e 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -36,12 +36,11 @@ module.exports = env => { appPath = "app", appResourcesPath = "app/App_Resources", - // Snapshot, uglify and report can be enabled by providing - // the `--env.snapshot`, `--env.uglify` or `--env.report` flags - // when running 'tns run android|ios' - snapshot, - uglify, - report, + // You can provide the following flags when running 'tns run android|ios' + production, // --env.production + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report } = env; const appFullPath = resolve(projectRoot, appPath); @@ -52,7 +51,7 @@ module.exports = env => { const vendorPath = `.${sep}vendor.js`; const config = { - mode: "development", + mode: production ? "production" : "development", context: appFullPath, watchOptions: { ignored: [ diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index a1dffcb3..910da06c 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -36,12 +36,11 @@ module.exports = env => { appPath = "app", appResourcesPath = "app/App_Resources", - // Snapshot, uglify and report can be enabled by providing - // the `--env.snapshot`, `--env.uglify` or `--env.report` flags - // when running 'tns run android|ios' - snapshot, - uglify, - report, + // You can provide the following flags when running 'tns run android|ios' + production, // --env.production + snapshot, // --env.snapshot + uglify, // --env.uglify + report, // --env.report } = env; const appFullPath = resolve(projectRoot, appPath); @@ -52,7 +51,7 @@ module.exports = env => { const vendorPath = `.${sep}vendor.ts`; const config = { - mode: "development", + mode: production ? "production" : "development", context: appFullPath, watchOptions: { ignored: [