leiyanting

导航

 
压缩js和html文件  压缩hmtl需要npm下载  html-webpack-plugin
                const { resolve } = require('path');
                const HtmlWebpackPlugin = require('html-webpack-plugin');

                module.exports = {
                entry: './src/js/index.js',
                output: {
                    filename: 'js/built.js',
                    path: resolve(__dirname, 'build')
                },
                plugins: [
                    new HtmlWebpackPlugin({
                    template: './src/index.html',
                    // 压缩html代码
                    minify: {
                        // 移除空格
                        collapseWhitespace: true,
                        // 移除注释
                        removeComments: true
                    }
                    })
                ],

                // 生产模式自动压缩js代码,不需要别的操作
                mode: 'production' //生产模式
                };

 

posted on 2021-10-22 08:59  leiyanting  阅读(43)  评论(0编辑  收藏  举报