在根目录新建配置文件webpack.config.js
//引入模块
const path = require('path');
module.exports = {
//打包文件是否为压缩格式
mode: "production",
entry: {
//打包文件的入口
main: './src/index.js',
}
output: {
//打包生成文件的名字
filename: 'bundle.js',
//打包生成文件的绝对路径
path: path.resolve(__dirname, 'dist')
}
}
如果想更换webpack.config.js配置文件名字如webpackconfig.js
npx webpack --config webpackconfig.js
运行webpack
npx webpack
配置完"scripts"之后运行webpack为
npm run bundle
{
"name": "lesson",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"bundle": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"webpack-cli": "^3.3.10"
},
"dependencies": {
"webpack": "^4.25.1"
}
}