多个 Vue/Webpack 中的 .env.development 配置文件。

huangapple go评论87阅读模式
英文:

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!

huangapple
  • 本文由 发表于 2020年1月6日 21:08:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定