html-webpack-plugin

简化创建 HTML 文件以服务于打包的插件,适用于 webpack 45 版本

https://github.com/jantimon/html-webpack-plugin

会生成一个 dist/index.html 的文件,使用如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  entry: "index.js",
  output: {
    path: __dirname + "/dist",
    filename: "index_bundle.js",
  },
  plugins: [new HtmlWebpackPlugin()],
};
1
2
3
4
5
6
7
8
9
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Webpack App</title>
    <script defer src="index_bundle.js"></script>
  </head>
  <body></body>
</html>