Skip to content

Commit

Permalink
feat(webpack): add html-webpack-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhuan committed Nov 12, 2024
1 parent f424b35 commit 3d8316d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion _posts/2024-11-12-webpack-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,31 @@ module.exports = merge(commonConfig, {
"build": "webpack --config webpack.prod.config.cjs",
}
}
```
```

## 插件 {#plugins}

### html-webpack-plugin

[`html-webpack-plugin`](https://github.com/jantimon/html-webpack-plugin) 可以简化 HTML 页面的创建。

```sh
pnpm add -D html-webpack-plugin
```

修改公共配置文件 `webpack.common.config.cjs`

```diff
+ const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
...
+ plugins: [new HtmlWebpackPlugin()],
}
```

`html-webpack-plugin` 的选项支持一些常见的参数:

- `title` 页面标题
- `filename` 输出的 HTML 文件名,默认是 `index.html`
- `template` 模板文件路径,默认是 `src/index.ejs`(如果存在的话)

0 comments on commit 3d8316d

Please sign in to comment.