env-cmd 从文件读取配置变量
npm install --registry=https://registry.npm.taobao.org -D env-cmd
So..
这样你在npm run build的时候会发现输出文件里面process.env.XXX
被替换为配置文件里面对应的常量.
build.ini
NODE_ENV=production
BACKEND_URL=foo.com
package.json
{
"name": "pack",
"version": "1.0.0",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --content-base ./dist --config config/dev.external.js",
"build": "env-cmd ./build.ini webpack --config config/production.external.js --progress --hide-modules",
"watch": "cross-env NODE_ENV=development webpack --config config/production.external.js --watch"
},
"devDependencies": {
"bootstrap": "^3.3.7",
"cross-env": "^3.0.0",
"crypto-js": "^3.1.9-1",
"css-loader": "^0.28.0",
"env-cmd": "^5.1.0",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.1",
"file-saver": "^1.3.3",
"html-webpack-plugin": "^2.28.0",
"less": "^2.7.2",
"less-loader": "^4.0.3",
"style-loader": "^0.16.1",
"url-loader": "^0.5.8",
"vue": "^2.3.3",
"vue-loader": "^11.3.4",
"vue-resource": "^1.3.1",
"vue-router": "^2.4.0",
"vue-template-compiler": "^2.3.3",
"vuex": "^2.3.1",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.2.0",
"webpack-merge": "^4.1.0"
}
}