1.安裝 webpack-dev-server
2.配置package.json "dev":"webpack-dev-server --config webpack.config.js"
3.配置編譯目標,在webpack.config.js中補充target:'web'
4.根據(jù)不同的環(huán)境判斷(開發(fā)環(huán)境/正式環(huán)境) 安裝cross-env
5.在package.json中,利用corss-env判斷環(huán)境.
"build": "cross-env NODE_ENV=production webpack --config webpack.config.js",
"dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack.config.js"
6.在webpack.config.js寫判斷邏輯
7.js需要加載到一個html里面運行,利用html-webpack-plugin 安裝它