From 9ea8c18e3a5d6699d716cc70befee39a7ee3e691 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Sat, 17 Mar 2018 15:53:05 +0200 Subject: [PATCH] fix-next: copy only the target platform App Resources When building for Android the App_Resources for iOS should be copied to the dist directory and vice-versa. --- templates/webpack.angular.js | 18 +++++++++++++----- templates/webpack.javascript.js | 16 ++++++++++++---- templates/webpack.typescript.js | 18 +++++++++++++----- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/templates/webpack.angular.js b/templates/webpack.angular.js index e4f7afb5..32e6d0e0 100644 --- a/templates/webpack.angular.js +++ b/templates/webpack.angular.js @@ -1,4 +1,4 @@ -const { resolve, join } = require("path"); +const { relative, resolve, join } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); @@ -15,13 +15,14 @@ module.exports = env => { throw new Error("You need to provide a target platform!"); } + const platforms = ["ios", "android"]; const projectRoot = __dirname; // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - const platforms = ["ios", "android"]; const { - // The 'appPath' and 'appResourcesDir' values are fetched from + // The 'appPath' and 'appResourcesPath' values are fetched from // the nsconfig.json configuration file // when bundling with `tns run android|ios --bundle`. appPath = "app", @@ -128,14 +129,21 @@ 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: `${appResourcesFullPath}/**`, context: projectRoot }, { from: "fonts/**" }, { from: "**/*.jpg" }, { from: "**/*.png" }, { from: "**/*.xml" }, - ]), + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), // Generate a bundle starter script and activate it in package.json new nsWebpack.GenerateBundleStarterPlugin([ "./vendor", diff --git a/templates/webpack.javascript.js b/templates/webpack.javascript.js index 997ddc6b..866192bf 100644 --- a/templates/webpack.javascript.js +++ b/templates/webpack.javascript.js @@ -1,4 +1,4 @@ -const { resolve, join } = require("path"); +const { relative, resolve, join } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); @@ -15,11 +15,12 @@ module.exports = env => { throw new Error("You need to provide a target platform!"); } + const platforms = ["ios", "android"]; const projectRoot = __dirname; // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - const platforms = ["ios", "android"]; const { // The 'appPath' and 'appResourcesPath' values are fetched from // the nsconfig.json configuration file @@ -111,14 +112,21 @@ 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: `${appResourcesFullPath}/**`, context: projectRoot }, { from: "fonts/**" }, { from: "**/*.jpg" }, { from: "**/*.png" }, { from: "**/*.xml" }, - ]), + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), // Generate a bundle starter script and activate it in package.json new nsWebpack.GenerateBundleStarterPlugin([ "./vendor", diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index 14214da0..a3d91f02 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -1,4 +1,4 @@ -const { resolve, join } = require("path"); +const { relative, resolve, join } = require("path"); const webpack = require("webpack"); const nsWebpack = require("nativescript-dev-webpack"); @@ -15,13 +15,14 @@ module.exports = env => { throw new Error("You need to provide a target platform!"); } + const platforms = ["ios", "android"]; const projectRoot = __dirname; // Default destination inside platforms//... const dist = resolve(projectRoot, nsWebpack.getAppPath(platform)); + const appResourcesPlatformDir = platform === "android" ? "Android" : "iOS"; - const platforms = ["ios", "android"]; const { - // The 'appPath' and 'appResourcesDir' values are fetched from + // The 'appPath' and 'appResourcesPath' values are fetched from // the nsconfig.json configuration file // when bundling with `tns run android|ios --bundle`. appPath = "app", @@ -113,14 +114,21 @@ 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: `${appResourcesFullPath}/**`, context: projectRoot }, { from: "fonts/**" }, { from: "**/*.jpg" }, { from: "**/*.png" }, { from: "**/*.xml" }, - ]), + ], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }), // Generate a bundle starter script and activate it in package.json new nsWebpack.GenerateBundleStarterPlugin([ "./vendor",