插件的目的在於解決loader沒法實現的其餘事html
因爲插件能夠攜帶參數/選項,你必須在webpack配置中,向plugins屬性傳入new實例。webpack
const HtmlWebpackPlugin = require('html-webpack-plugin'); //經過 npm 安裝 const webpack = require('webpack'); //訪問內置的插件 const path = require('path'); const config = { entry: './path/to/my/entry/file.js', output: { filename: 'my-first-webpack.bundle.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.(js|jsx)$/, use: 'babel-loader' } ] }, plugins: [ new webpack.optimize.UglifyJsPlugin(), new HtmlWebpackPlugin({template: './src/index.html'}) ] }; module.exports = config;