VUE为NX插件和使用环境变量(NX-Plus/Vue)
我已经将VUE应用程序迁移到NX,现在一切都很好,除了一件事 - 以前,.env
文件在开发环境和开发过程中均在开发和构建过程中使用,vue -Cli-Service
处理了这一点。现在我在应用程序构建方面遇到困难 - 它似乎没有读取.ENV文件,否则我只是做错了。
我尝试添加dotenv-webpack
,并将其添加到configure-webpack.js
中,但是在构建过程中,没有一个变量无法访问。这是文件示例:
//.env
SOME_API_URL=$API_URL
// config.ts
export const CONFIG = {
api_url = process.env.SOME_API_URL
}
// during build process.env is undefined
构建命令如下:
export API_URL='http://vue-app.com'; nx build frontend --skip-nx-cache
I've migrated vue app to nx, all is fine now except of one thing - previously, .env
file was used in both dev and production environments, during development as well as build, vue-cli-service
took care of that. Now I struggle with app build - it doesn't seem to read .env file, or I just do it wrong.
I've tried to add dotenv-webpack
and add it in the configure-webpack.js
but during build none of the variables was accessible. Here is the file example:
//.env
SOME_API_URL=$API_URL
// config.ts
export const CONFIG = {
api_url = process.env.SOME_API_URL
}
// during build process.env is undefined
build command looks like this:
export API_URL='http://vue-app.com'; nx build frontend --skip-nx-cache
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要切换到VITE,但是我们使用此插件在我们的应用程序中取得了良好的成功: https://github.com/chf007/vite-plugin-nx-dotenv
You would need to switch to Vite but we’ve had good success using this plugin for our applications: https://github.com/chf007/vite-plugin-nx-dotenv