Webpack 初始化
本文最后更新于:2024年3月18日 凌晨
Webpack 初始化
安装Webpack
1
| yarn add -D webpack webpack-cli
|
配置运行脚本
1 2 3 4 5 6
| "scripts": { "clean": "rm dist/bundle.js", "build": "webpack", "build-dev": "webpack --mode development", "build-prod": "webpack --mode production", },
|
编写配置文件
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
:可省略的扩展名。
打包