-
安装项目全部依赖包:
npm install
-
安装生产环境依赖包:(即package.json文件中的dependencies部分)
npm install --production
配置生产和开发并行
- 在
webpack.config.js
中配置生产和开发的地址
let address = {}
if(process.env.type == "build"){ //process.env获取当前系统环境信息的对象,常规可以用来进一步获取环境变量、用户名等系统信息
address["publicPath"] = "http://cdn.jspang.com"
}else{
address["publicPath"] = "http://192.168.2.153:1117/"
}
- 在
package.json
中设置scripts的命令
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "webpack-dev-server --open",
"dev": "set type=dev&webpack", //添加type=dev,那样process.env.type就可以获取到type的值
"build": "set type=build&webpack"
}
ps:mac的package.json配置set要替换成export,并且要多加一个&符
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"server": "webpack-dev-server --open",
"dev": "export type=dev&&webpack",
"build": "export type=build&&webpack"
}