webpack5 upgrade: compiler.plugin is not a function compilation error

  1. Background: Upgrade webpack5 + use preload plug-in
  2. Error message:compiler.plugin is not a function
  3. Key code: Manually introduce the preload plug-in
const PreloadWebpackPlugin = require('preload-webpack-plugin')

plugins: [
        new PreloadWebpackPlugin({
    
    
            rel: 'prefetch',
            fileBlacklist:[/.*\.(js|map|css)$/]
        })
],
  1. Problem: According to webpack5 source code analysis, webpack5 is incompatible with the preload plug-in, causing an error; except for the preload plug-in, any plug-in that is incompatible with webpack5 will cause an error.
  2. Solution: Alternatives to the preload plug-in can be used, but the configuration information cannot be completely replaced and needs to be checked one by one.
const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin')

plugins: [
        new PreloadWebpackPlugin({
    
    
            rel: 'prefetch',
            fileBlacklist:[/.*\.(js|map|css)$/]
        })
],

Guess you like

Origin blog.csdn.net/qq_44242707/article/details/127567731