安装webpack
npm install -g webpack webpack-cli
查看版本
webpack -v
common.js
exports.info = function(str){
document.write(str)
}
utils.js
exports.add = function(a,b){
return a+b;
}
main.js
const common =require("./common.js");
const utils =require("./utils.js");
common.info("hello common "+ utils.add(2,3))
创建webpack配置文件,名称是固定的 webpack.config.js
const path = require("path"); //node内置
module.exports={
entry:"./src/main.js", //配置文件入口
output:{
path:path.resolve(__dirname,'./dist'),
filename: "bundle.js"
}
}
webpack 打包
webpack #会有黄色警告
webpack --mode =development # 没有警告