use DefinePlugin to define a variable
启动
// package.json
{
"scripts": {
"dev": "webpack-dev-server --inline --hot --env.dev",
"build": "rm -rf dist && webpack -p --progress --hide-modules --env.prod"
}
}
环境配置
// prod.env.js
module.exports = {
NODE_ENV: '"production"',
API_URL: JSON.stringify('http://wxn.ykyd0417.com/school/api')
}
// webpack.config.js
plugins: [
new webpack.DefinePlugin({
'process.env': (options.dev ? require('./config/dev.env') : require('./config/prod.env'))
})
//....
]
使用
// config.js
baseURL: process.env.API_URL