51.png

1 - 生成一个npm仓库

  1. yarn init -y

2- 安装依赖

  1. yarn add webpack webpack-cli

3 - 新建.gitignore 文件

  1. node_modules
  2. dist
  3. yarn.lock
  4. src(main.js)

4 - 构件核心文件 (webpack.config.js)

52.png

  1. // webpack.config.js
  2. const webpack = require("webpack");
  3. const path = require("path");
  4. const config = {
  5. entry:path.resolve(__dirname,'src/main.js'), //入口文件
  6. output:{ //出口文件
  7. path:path.resolve(__dirname,'dist'),
  8. filename:'bundle.js'
  9. },
  10. mode:'development' //模式
  11. }
  12. module.exports = config;

5 - 配置package.json文件

53.png

6 - 打包

会在dist目录下生成bundle.js文件(自定义的出口文件名)

  1. npm run build
  2. yarn serve