webpack 之 插件 html-webpack-plugin
文档地址:https://webpack.js.org/plugins/html-webpack-plugin/
中文文档:https://www.html.cn/doc/webpack2/plugins/html-webpack-plugin/
🌈作用
简化html的创建,生成html5文件,并把打包好的webpack bundle这个js自动引入这个h5文件内。
🌈基本用法(代码示例)
安装: $ npm install html-webpack-plugin --save-dev
var HtmlWebpackPlugin = require('html-webpack-plugin'); var webpackConfig = { entry: 'index.js', output: { path: 'dist', filename: 'index_bundle.js' }, plugins: [new HtmlWebpackPlugin()] };
以上代码添加到webpack配置中,就会在dist路径下生成一个index.html,并且自动引入 index_bundle.js文件。