From 044b1bb84225b96c3c1ab47d7b37398b8649cf9f Mon Sep 17 00:00:00 2001 From: Yoshie Muranaka Date: Wed, 12 Aug 2020 14:12:44 -0700 Subject: Add env variable check to improve build customizations Added flags for styles, router, and store. If these flags are set to true, then webpack will attempt to resolve the environment specific files. If these flags are not explicitly set to true, the default files are used. This will give us more flexibility and remove the need to create empty env files (eg env/router/ibm.js). Signed-off-by: Yoshie Muranaka Change-Id: I552ad402621a3bbad3e871076a894ecadf9e82c7 --- vue.config.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'vue.config.js') diff --git a/vue.config.js b/vue.config.js index 81763622..1e17def0 100644 --- a/vue.config.js +++ b/vue.config.js @@ -6,7 +6,9 @@ module.exports = { sass: { prependData: () => { const envName = process.env.VUE_APP_ENV_NAME; - if (envName !== undefined) { + const hasCustomStyles = + process.env.CUSTOM_STYLES === 'true' ? true : false; + if (hasCustomStyles && envName !== undefined) { // If there is an env name defined, import Sass // overrides. // It is important that these imports stay in this @@ -14,7 +16,7 @@ module.exports = { // take precedence over the default BMC styles return ` @import "@/assets/styles/bmc/helpers"; - @import "@/env/assets/styles/_${process.env.VUE_APP_ENV_NAME}"; + @import "@/env/assets/styles/_${envName}"; @import "@/assets/styles/bootstrap/_helpers"; `; } else { @@ -51,6 +53,8 @@ module.exports = { productionSourceMap: false, configureWebpack: config => { const envName = process.env.VUE_APP_ENV_NAME; + const hasCustomStore = process.env.CUSTOM_STORE === 'true' ? true : false; + const hasCustomRouter = process.env.CUSTOM_ROUTER === 'true' ? true : false; if (process.env.NODE_ENV === 'production') { config.plugins.push( @@ -59,11 +63,16 @@ module.exports = { }) ); } + if (envName !== undefined) { - // Resolve store and router modules in src/main.js - // depending on environment (VUE_APP_ENV_NAME) variable - config.resolve.alias['./store$'] = `./env/store/${envName}.js`; - config.resolve.alias['./router$'] = `./env/router/${envName}.js`; + if (hasCustomStore) { + // If env has custom store, resolve store module in src/main.js + config.resolve.alias['./store$'] = `./env/store/${envName}.js`; + } + if (hasCustomRouter) { + // If env has custom router, resolve router module in src/main.js + config.resolve.alias['./router$'] = `./env/router/${envName}.js`; + } } }, chainWebpack: config => { -- cgit v1.2.3