Upgrade webpack5 + vue-cli5

This article only focuses on the overall upgrade. The specific and subtle pitfall experiences will be continued to be updated in the same column.

webpack upgrade

core steps

  1. Upgrade webpack:npm install webpack@latest
  2. Upgrade webpack-cli:npm install webpack-cli@latest

Plug-in related

  1. Upgrade mini-css-extract-plugin:npm install mini-css-extract-plugin@latest
  2. Upgrade html-webpack-plugin:npm install html-webpack-plugin@latest
  3. IgnorePlugin syntax modification
new webpack.IgnorePlugin({
    
    
    resourceRegExp: /^\.\/locale$/,
    contextRegExp: /moment/,
})

other

  1. Turn on persistent cache: manually turn it on to generate a webpack5 cache directory to improve packaging speed.
cache: {
    
    
    type: 'filesystem',
}
  1. Node.js related polyfill: webpack5 has been removed and needs to be introduced manually
resolve: {
    
    
    fallback:  {
    
    
        "path": require.resolve("path-browserify"),
        "crypto": require.resolve("crypto-browserify"),
    }
}
  1. Strict devtool writing:^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$

vue-cli upgrade

core steps

  1. Upgrade vue/cli-service: npm install @vue/cli-service@latest(underlying webpack5)
  2. Upgrade webpack: npm install webpack@latest(the webpack version is consistent with the vue-cli version)

other

  1. Turn on persistent cache: manually turn it on to generate a webpack5 cache directory to improve packaging speed.
cache: {
    
    
    type: 'filesystem',
}
  1. Node.js related polyfill: webpack5 has been removed and needs to be introduced manually
resolve: {
    
    
    fallback:  {
    
    
        "path": require.resolve("path-browserify"),
        "crypto": require.resolve("crypto-browserify"),
    }
}
  1. IgnorePlugin syntax modification
new webpack.IgnorePlugin({
    
    
    resourceRegExp: /^\.\/locale$/,
    contextRegExp: /moment/,
})

Guess you like

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