Webpack 初始化

本文最后更新于:2024年3月18日 凌晨

Webpack 初始化

安装Webpack

1
yarn add -D webpack webpack-cli

配置运行脚本

  • ./package.json
1
2
3
4
5
6
"scripts": {
"clean": "rm dist/bundle.js",
"build": "webpack",
"build-dev": "webpack --mode development",
"build-prod": "webpack --mode production",
},

编写配置文件

  • ./webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const webpack = require('webpack');
const path = require('path');

const config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
resolve: {
extensions: [".js", ".json", ".jsx", ".css", ".vue"],
},
};

module.exports = config;
  • entry:入口。
  • output:出口。
  • extensions:可省略的扩展名。

打包

1
$ yarn build

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!