首先需要安装node、webpack、webpack-cli
一、命令方式打包
webpack ‘入口文件‘ -o ‘输出文件‘ --mode=‘使用模式‘,例如:
webpack ./src/main.js -o ./build/index.js --mode=development
二、配置文件方式打包
一个简单的webpack.config.js的配置文件如下
const path = require(‘path‘)
module.exports = {
    entry: "./src/main.js",
    output:{
        filename: ‘index.js‘,
        path:path.resolve(__dirname, ‘build‘)
    },
    module:{
        rules:[
            {
                test: /\.css$/,
                use:[
                    "style-loader",
                    "css-loader"
                ]
            }
        ]
    },
    plugins:[
    ],
    mode:‘development‘
}
设置完成后直接运行webpack即可。
原文:https://www.cnblogs.com/qiaoyun/p/13258081.html