1.初次用webpack打包js模块
(1)安装webpack
cnpm i webpack --save-dev
cnpm i webpack-cli --save-dev
(2)创建index.js文件
function add(x, y) {//1.初次输入命令打包
return x + y;
}
console.log(add(2, 3));
(3) 运行命令打包
开发环境指令:
webpack ./src/index.js -o ./build/build.js --mode=development
webpack以./src/index.js为入口文件开始打包,打包后会输出./build/build.js整体打包环境
生产环境指令:
webpack ./src/index.js -o ./build/build.js --mode=production
2.小结:
1.webpack能处理js/json文件;不能处理css,img
2.生产环境比开发环境多了一个代码压缩