项目目录中,安装webpack包:

    1. npm install webpack webpack-cli --save-dev

    新建webpack.config.js文件,写入:

    1. const path = requaire('path');
    2. module.exports = {
    3. entry: './src/main.js', # main js file
    4. output: {
    5. filename: 'bundle.js', # output file
    6. path: path.resolve(__dirname, 'dist')
    7. },
    8. optimization: {
    9. minimize: false
    10. },
    11. target: 'node'
    12. };

    package.json中写入:

    1. {
    2. ...
    3. "scripts": {
    4. "build": "webpack --mode production",
    5. ...
    6. },
    7. ...
    8. }

    然后就可以build了:

    1. npm run build

    生成的dist目录中的bundle.js就是打包完的文件。