我正在尝试使用Grunt来读取特定于环境的JSON文件。但它始终从default.json文件中读取。我错过了什么吗?
以下是Gruntfile.js
var config = require('config');
var host = config.get('host');
console.log(host);
这是我的package.json
{
"name": "grunt",
"version": "1.0.0",
"description": "Test app",
"main": "grunt.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Me,
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"load-grunt-config": "^0.17.2",
"load-grunt-tasks": "^3.2.0"
}
}
我有
host=localhost
和中的 default.json
host=someURL
production.json
命令我在命令行中运行
$ set NODE_ENV="production"
$ grunt
localhost
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
答案 0 :(得分:0)
我做到了。我使用SET
代替export
来设置NODE_ENV
。
$ export NODE_ENV=production