处理html

$_> npm i -D html-webpack-plugin
// webpack.config.js
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: {
        index: './src/index.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
    },
    module: {
        rules: []
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'html/index.html',
            template: './index.html',
            inject: false, // 是否自动引入入口文件
            minify: { // 压缩
                collapseInlineTagWhitespace: true,
                collapseWhitespace: true
            },
            chunks: ['index'] // 移入某个文件,配置 inject: 'body'
        })
    ],
    mode: 'development'
};

你可能感兴趣的:(处理html)