[英]Reading webpack's .env files with grunt
I'm using grunt-replace to perform some substitutions of variables according to the environment (dev/testing/production).我正在使用grunt-replace根据环境(开发/测试/生产)执行一些变量替换。 Those variables are set like this:
这些变量设置如下:
config: {
dev: {
options: {
variables: {
base_url: 'localhost'
}
}
},
testing: {
options: {
variables: {
base_url: 'testing.example.com'
}
}
},
prod: {
options: {
variables: {
base_url: 'production.example.com'
}
}
}
},
Then I'm replacing the variables with grunt-replace , like this:然后我用grunt-replace 替换变量,如下所示:
replace: {
main: {
options: {
patterns: [
{
match: 'BASE_URL',
replacement: '<%= grunt.config.get("base_url") %>'
}
]
},
src: 'src/main.js' ,
dest: 'dist/main.js'
},
}
Since I'm using an .env
file configured for the mentioned environments, is it possible to tell grunt-env to load that file and perform the replacements in replacement of grunt-config ?由于我使用的是为上述环境配置的
.env
文件,是否可以告诉 grunt-env 加载该文件并执行替换来替换grunt-config ? I would like to do this in order to avoid having duplicated code for setting those variables in each environment along both webpack and grunt.我想这样做是为了避免在 webpack 和 grunt 的每个环境中设置这些变量的重复代码。
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.