文:非凡主力著
根目录下运行一下命令:
cnpm init
–enter
cnpm install webpack -D
cnpm install webpack-dev-server -D
根目录(package.json 同级)下新建:
webpack.config.js ——>
//webpack配置文件
module.exports = {
//入口文件的配置项(不引报错)
entry: './src/scripts/help_center.js', //以当前位置引入
//出口文件配置项
output: {
},
//配置webpack开发服务功能
devServer: {
host: 'localhost',
port: 9000,
//服务器代理配置项
proxy: {
'/help':{
target:'http://10.153.29.39:9036',
secure:true,
changeOrigin:true
/*
//不显示/help
pathRewrite: {
'^/help': ''
}
*/
}
}
}
}
启动时如果报错检查:
package.json——>
{
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
//这里添加 dev:才能运行命令
"dev": "webpack-dev-server"
},
"devDependencies": {
"webpack": "^3.8.1",
"webpack-dev-server": "^2.5.0"
}
}
运行命令:npm run dev
文:非凡主力著