一、webpack安装
1、全局安装
npm inistall -g webpack@3.11.0
2、局部安装
npm init –y
npm inistall webpack@3.11.0 –save-dev
二、 webpack模块化打包
1、用命令行的形式打包
webpack [entry] [output]
webpack ./js/index.js ./dist/main.js
2、使用配置文件【 webpack.config.js
】的形式打包
const path = require("path");
module.exports={
//相对路径
// entry:"./js/index.js",
entry:{
index:"./js/index.js"
},
output:{
filename:"[name][hash:8].js",
//绝对路径
path:path.resolve(__dirname,"dist")
}
}
webpack --config webpack.conf.js
3、使用配置文件【 webpackfile.js
】的形式打包
const path = require("path");
module.exports={
//相对路径
entry:"./js/index.js",
output:{
filename:"main2.js",
//绝对路径
path:path.resolve(__dirname,"dist")
}
}
webpack --config webpackfile.js
5、使用npm配置文件
npm init –y
package.json 配置 build
{
"name": "01_ES(Module)",
"version": "1.0.0",
"description": "",
"main": "webpack.conf.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build":"webpack --config webpack.conf.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
npm run build