Open bluepeople1 opened 3 years ago
Is there any workaround? I faced this issue too. Explanation: If you use modern build and use .env variables with dotenv-expand and have '$' sign in your vars with backslash
VUE_APP_BASE_URL=\$BASE_URL
First (legacy build) will be ok, but modern will get all variables with '$' - empty, cause on second run it identifies it as a reference to another variable which doesn't exist.
that works
// .env
VUE_APP_URL = '\${ENV_APP_URL}'
module.exports = {
publicPath: process.env.VUE_APP_URL,
}
@bluepeople1 @onemantooo
VUE_APP_URL = '\${ENV_APP_URL}'
Not worked for me. Still getting empty strings in modern build js code.
Solved only by extra dirty hack:
// .env
VUE_APP_BASE_URL=#DOLLAR_FIXER#DOCKER_ENV_BASE_URL
// vue.config.js
if (process.env.NODE_ENV == "production") {
console.log("Hacking #DOLLAR_FIXER#");
plugins.push(
new ReplaceInFileWebpackPlugin([
{
dir: "dist",
test: [/\.js$/, /\.html$/],
rules: [
{
search: /#DOLLAR_FIXER#/gi,
replace: "$",
},
],
},
])
);
}
Version
5.0.0-beta.0
Environment info
Steps to reproduce
1.vue.config.js 中设置publicPath:process.env.VUE_APP_URL 2..env文件中 VUE_APP_URL = '\${ENV_APP_URL}
What is expected?
What is actually happening?
1.@vue/cli-service/lib/commands/build/index.js中以下代码的问题,新起spawn中继承了主进程中process.env变量 process.env.VUE_CLI_MODERN_MODE = true if (!process.env.VUE_CLI_MODERN_BUILD) { // main-process for legacy build const legacyBuildArgs = { ...args, moduleBuild: false, keepAlive: true } await build(legacyBuildArgs, api, options)
2.dotenv-expand/lib/main.js 中
for (var configKey in config.parsed) { var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey]
} 中环境变量继承主进程process.env导致modern代码出错