简体   繁体   English

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

[英]Multiple .env.development configs in Vue/Webpack

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).我想为我的本地 Vue.js 项目使用两个不同的配置(使用 vue-cli 3)。

  • the first having VUE_APP_API_URL on my localhost,第一个在我的本地主机上有 VUE_APP_API_URL,
  • the other connecting to a development/staging server另一个连接到开发/登台服务器

So, I want to have .env.development-1 and .env-development-2 or something like that;所以,我想要.env.development-1.env-development-2或类似的东西; 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?我将如何解决这个问题?

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我刚刚做了一个.env.staging ,其中VUE_APP_API_URL指向登台服务器,其他一切都一样

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!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 .env.development 而不是 .env 时 process.env 返回 undefined - process.env returns undefined when using .env.development instead of .env 运行 cross-env NODE_ENV=development webpack-dev-server --open --hot 时,无法在 vue js 中使用 .env 文件 - Can't use .env file in vue js while running cross-env NODE_ENV=development webpack-dev-server --open --hot Vue和Webpack:全球开发和生产变量 - Vue & Webpack: Global development and production variables 如何为 webpack 设置多个环境变量? - How to set multiple env variables for webpack? 在TypeScript中使用Vue的故事书如何从.storybook.ts文件导入(Webpack配置)? - Storybook with Vue in TypeScript how to import from a .storybook.ts file (Webpack configs)? 为什么React app的生成版本(使用Webpack和Babel)使用错误的开发环境与HMR,这会导致错误? - Why does production build of React app (with Webpack and Babel) use wrong development env with HMR, which causes errors? 在多构建 Vue js 应用程序中定义多个配置的最佳方法是什么? - What is the best way to define multiple configs in a multi-build Vue js app? Vue.js + Webpack请求多个不正确的资源URL - Vue.js + Webpack Requesting Multiple Incorrect Resource URLs laravel webpack.mix 多语言vue,react - laravel webpack.mix with multiple language vue, react React-开发和生产中的环境变量 - React - Env variables in development AND production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM