1. 程式人生 > 其它 >webpack踩坑日記

webpack踩坑日記

https://www.cnblogs.com/BetterMan-/p/9867642.html 這是一個大佬的總結,但是我用webpack5重寫該demo時,發現了幾個有問題的地方
1:CleanWebpackPlugin
應該這樣:

const { CleanWebpackPlugin } = require("clean-webpack-plugin");
plugins: [
    new CleanWebpackPlugin(),  // 所要清理的資料夾名稱
  ]

2、merge

應該這樣:

const { merge } = require('webpack-merge');

3、分離css 使用demo中的回報錯extract-text-webpack-plugin報錯TypeError: Cannot set property 'index' of undefined 查了原因是因為我我使用的版本是webpack5.x 而在webpack5.中分離css的配置如下:

const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'css/[name].css',
      chunkFilename: "css/[id].css"
    })
  ]

4、增加css字首 (webpack5中測試未生效)

5、消除冗餘css (webpack5中報錯compiler.plugin is not a function)
6、未測試處理圖片 plugin

長風破浪會有時,直掛雲帆濟滄海