From ec9dc17d9a6fd7ef1df1b2c2f2d1891573d034bb Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Thu, 31 Jan 2019 11:47:31 +0200 Subject: [PATCH 1/3] refactor: skip copying of the native app resources on `tns preview` --- templates/webpack.angular.js | 20 ++++++++++++-------- templates/webpack.javascript.js | 20 ++++++++++++-------- templates/webpack.typescript.js | 20 ++++++++++++-------- templates/webpack.vue.js | 18 ++++++++++++------ 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index ee8250f5..87fca3a7 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -237,14 +237,6 @@ module.exports = env => { }), // Remove all files from the out dir. new CleanWebpackPlugin([`${dist}/**/*`]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), // Copy assets to out dir. Add your own globs as needed. new CopyWebpackPlugin([ { from: { glob: "fonts/**" } }, @@ -265,6 +257,18 @@ module.exports = env => { ], }; + // Copy the native app resources to the out dir + // only if doing a full build (tns run/build) and not previewing (tns preview) + if (env.externals.length === 0) { + config.plugins.push(new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ])); + } + if (report) { // Generate report files for bundles content diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 96fa1e62..1e16f8f6 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -194,14 +194,6 @@ module.exports = env => { }), // Remove all files from the out dir. new CleanWebpackPlugin([ `${dist}/**/*` ]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), // Copy assets to out dir. Add your own globs as needed. new CopyWebpackPlugin([ { from: { glob: "fonts/**" } }, @@ -225,6 +217,18 @@ module.exports = env => { ], }; + // Copy the native app resources to the out dir + // only if doing a full build (tns run/build) and not previewing (tns preview) + if (env.externals.length === 0) { + config.plugins.push(new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ])); + } + if (report) { // Generate report files for bundles content config.plugins.push(new BundleAnalyzerPlugin({ diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index fd3bdb28..9f0a77c3 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -207,14 +207,6 @@ module.exports = env => { }), // Remove all files from the out dir. new CleanWebpackPlugin([ `${dist}/**/*` ]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([ - { - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot - }, - ]), // Copy assets to out dir. Add your own globs as needed. new CopyWebpackPlugin([ { from: { glob: "fonts/**" } }, @@ -238,6 +230,18 @@ module.exports = env => { ], }; + // Copy the native app resources to the out dir + // only if doing a full build (tns run/build) and not previewing (tns preview) + if (env.externals.length === 0) { + config.plugins.push(new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ])); + } + if (report) { // Generate report files for bundles content config.plugins.push(new BundleAnalyzerPlugin({ diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 043d0a9f..d02c167d 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -216,12 +216,6 @@ module.exports = env => { }), // Remove all files from the out dir. new CleanWebpackPlugin([`${dist}/**/*`]), - // Copy native app resources to out dir. - new CopyWebpackPlugin([{ - from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, - to: `${dist}/App_Resources/${appResourcesPlatformDir}`, - context: projectRoot, - }]), // Copy assets to out dir. Add your own globs as needed. new CopyWebpackPlugin([ { from: { glob: "fonts/**" } }, @@ -245,6 +239,18 @@ module.exports = env => { ], }; + // Copy the native app resources to the out dir + // only if doing a full build (tns run/build) and not previewing (tns preview) + if (env.externals.length === 0) { + config.plugins.push(new CopyWebpackPlugin([ + { + from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, + to: `${dist}/App_Resources/${appResourcesPlatformDir}`, + context: projectRoot + }, + ])); + } + if (report) { // Generate report files for bundles content config.plugins.push(new BundleAnalyzerPlugin({ From 8212ccacb5c8ec6455805025cd9ef3f036fa1b2c Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 5 Mar 2019 15:18:36 +0200 Subject: [PATCH 2/3] refactor(webpack.config.spec.ts): extract a variable from a function invocation --- templates/webpack.config.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/webpack.config.spec.ts b/templates/webpack.config.spec.ts index 74c6f41e..ee5a62dc 100644 --- a/templates/webpack.config.spec.ts +++ b/templates/webpack.config.spec.ts @@ -83,7 +83,8 @@ describe('webpack.config.js', () => { }); it('returns empty array when externals are not passed', () => { - const config = webpackConfig(getInput({ platform })); + const input = getInput({ platform }); + const config = webpackConfig(input); expect(config.externals).toEqual([]); }); From 748591e79aa59c459f069d903d9829f2d54bbe95 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 5 Mar 2019 15:23:41 +0200 Subject: [PATCH 3/3] fix: check for parsed externals length and guard against undefined/null property access --- templates/webpack.angular.js | 2 +- templates/webpack.javascript.js | 2 +- templates/webpack.typescript.js | 2 +- templates/webpack.vue.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index 966b9a05..a10d2b96 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -271,7 +271,7 @@ module.exports = env => { // Copy the native app resources to the out dir // only if doing a full build (tns run/build) and not previewing (tns preview) - if (env.externals.length === 0) { + if (!externals || externals.length === 0) { config.plugins.push(new CopyWebpackPlugin([ { from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index d845718d..c98cdad7 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -226,7 +226,7 @@ module.exports = env => { // Copy the native app resources to the out dir // only if doing a full build (tns run/build) and not previewing (tns preview) - if (env.externals.length === 0) { + if (!externals || externals.length === 0) { config.plugins.push(new CopyWebpackPlugin([ { from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 38ead95c..ec088514 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -239,7 +239,7 @@ module.exports = env => { // Copy the native app resources to the out dir // only if doing a full build (tns run/build) and not previewing (tns preview) - if (env.externals.length === 0) { + if (!externals || externals.length === 0) { config.plugins.push(new CopyWebpackPlugin([ { from: `${appResourcesFullPath}/${appResourcesPlatformDir}`, diff --git a/templates/webpack.vue.js b/templates/webpack.vue.js index 9537a139..4ad892d3 100644 --- a/templates/webpack.vue.js +++ b/templates/webpack.vue.js @@ -248,7 +248,7 @@ module.exports = env => { // Copy the native app resources to the out dir // only if doing a full build (tns run/build) and not previewing (tns preview) - if (env.externals.length === 0) { + if (!externals || externals.length === 0) { config.plugins.push(new CopyWebpackPlugin([ { from: `${appResourcesFullPath}/${appResourcesPlatformDir}`,