1. 程式人生 > 其它 >webpack5 學習筆記(13)

webpack5 學習筆記(13)

技術標籤:webpackwebpack

webpack js和html壓縮處理

js壓縮只需要在webpack.config.js裡更改mode配置為production即可

html壓縮處理需要在webpack.config.js進行相關更改:

const HtmlWebpackPlugin = require("html-webpack-plugin");
const { resolve } = require('path')

module.exports = {
    entry: './src/js/index.js',
    output: {
        filename: 'js/built.js',
        path: resolve(__dirname, 'build')
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './src/index.html',
            minify:{
                //移出空格
                collapseWhitespace:true,
                //移出註釋
                removeComments:true
            }
        })
    ],
    mode: 'production'
}