英文:
Multiple .env.development configs in Vue/Webpack
问题
我觉得这不应该是一件难事,但我无法让它运行。
我想在我的本地Vue.js项目(使用vue-cli 3)中有两个不同的配置。
- 第一个在我的本地主机上有VUE_APP_API_URL,
- 另一个连接到开发/预发布服务器
所以,我想有.env.development-1
和.env-development-2
之类的东西;只是一种快速切换两个否则相同的配置文件的方式。
我已经了解了构建模式等内容,但这些文章似乎都针对“构建”。我只想用不同的配置运行本地开发服务器。
我该如何解决这个问题?
英文:
I feel this should not be a hard thing to do, but I can't get it to run.
I want to have two different configs for my local Vue.js project (using vue-cli 3).
- the first having VUE_APP_API_URL on my localhost,
- the other connecting to a development/staging server
So, I want to have .env.development-1
and .env-development-2
or something like that; just a way to quickly switch between two otherwise identical configuration files.
I've read about build modes etc, but those articles all seem to target "building". I just want to run local devserver with a different config.
How would I solve this?
答案1
得分: 1
感谢在我的原始帖子下面的评论,我发现解决方案实际上非常简单:
我只是创建了一个名为.env.staging
的文件,其中VUE_APP_API_URL
指向了暂存服务器,其他一切保持不变。
然后
"scripts": {
"serve:local": "vue-cli-service serve",
"serve:staging": "vue-cli-service serve --mode staging",
}
然后它就能工作了。
一开始需要理解这个概念。
谢谢!
英文:
Thanks to the comments under my original post, i found out that the solution is, in fact, really easy:
i just made an .env.staging
with the VUE_APP_API_URL
pointing to the staging server, everything else being the same
then
"scripts": {
"serve:local": "vue-cli-service serve",
"serve:staging": "vue-cli-service serve --mode staging",
}
and it works.
first had to wrap my head around the concept.
thanks!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论