[英]NodeJS environment variables in Grunt
我正在將我的項目從簡單的node server.js
轉移到使用Grunt。
我曾經直接從webstorm運行我的應用程序,並且會為我設置環境變量。
我怎樣才能在Grunt中實現同樣的目標?
我需要從webstorm(windows)運行grunt,或者在運行grunt(顯式)時設置env變量
這在部署時不是問題,因為heroku已經負責設置我的環境變量。
使用grunt-env插件: https : //npmjs.org/package/grunt-env
並設置您的配置:
grunt.initConfig({
env : {
options : {
//Shared Options Hash
},
dev : {
NODE_ENV : 'development',
DEST : 'temp'
}
},
'another-task': {}
});
在你的gruntfile中你可能會定義一些默認任務:
grunt.registerTask('default', ['env', 'another-task']);
因此,如果您首先運行'grunt default',則設置env-vars,然后運行'another-task'
如果要通過命令行選項指定當前環境,可以使用grunt.option:
grunt.initConfig({
env : {
options : {
//Shared Options Hash
},
dev : {
NODE_ENV : grunt.option('environment') || 'development',
DEST : 'temp'
}
},
在此示例中,如果使用--environment=production
生產--environment=production
生產--environment=production
生產,則將設置--environment=production
生產
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.