Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义配置文件路径问题 #5584

Closed
mino01x opened this issue Jun 15, 2020 · 2 comments · Fixed by #5598
Closed

自定义配置文件路径问题 #5584

mino01x opened this issue Jun 15, 2020 · 2 comments · Fixed by #5598
Labels

Comments

@mino01x
Copy link

mino01x commented Jun 15, 2020

Version

4.4.4

Environment info

  System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Binaries:
    Node: 11.11.0 - ~/.nvm/versions/node/v11.11.0/bin/node
    Yarn: 1.16.0 - ~/.nvm/versions/node/v11.11.0/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.11.0/bin/npm

Steps to reproduce

VUE_CLI_SERVICE_CONFIG_PATH=$PWD/vue.lib-config.js vue-cli-service lib --sourceMap

What is expected?

读取项目文件夹下的vue.lib-config.js配置文件

What is actually happening?

实际上读取的是同级文件夹下的vue.config.js配置文件

const possibleConfigPaths = [
process.env.VUE_CLI_SERVICE_CONFIG_PATH,
'./vue.config.js',
'./vue.config.cjs'
]
let fileConfigPath
for (const p of possibleConfigPaths) {
const resolvedPath = p && path.resolve(this.context, p)
if (resolvedPath && fs.existsSync(resolvedPath)) {
fileConfigPath = resolvedPath
}
}

之前是通过VUE_CLI_SERVICE_CONFIG_PATH环境变量自定义配置文件路径,请问现在是会被 ./vue.config.js ./vue.config.cjs替换么

@mino01x mino01x changed the title 自定义vue配置文件设置问题 自定义配置文件路径问题 Jun 15, 2020
@haoqunjiang
Copy link
Member

这个 for 循环漏了个 break 的逻辑。

不过,为什么要用这么 hacky 的方式加载配置文件?VUE_CLI_SERVICE_CONFIG_PATH 不是公开的 API。你的需求更适合在 vue.config.js 里根据其他环境变量进行条件判断,然后返回不同的配置。

@mino01x
Copy link
Author

mino01x commented Jun 15, 2020

是的 开始是放在vue.config.js中判断,后面发现有这个环境变量就拿来试试了 省了判断的逻辑。这么用确实不好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants