webpack5 學習筆記(13)
阿新 • • 發佈:2021-01-16
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' }