一、代码分割优化

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');  // 注入html
const CleanWebpackPlugin = require('clean-webpack-plugin');
const merge = require('webpack-merge');

const webpackBaseConf = require('./webpack.base.conf');
const webpackProConf = {
  mode: 'production',
  devtool: 'source-map',
  optimization: {
    runtimeChunk: 'single',
    splitChunks: {
      chunks: 'all',
      minSize: 30000,
      minChunks: 1,
      cacheGroups: {
        vendors: {
          test: /[\\/]node_modules[\\/]/,
          priority: -10
        },
        default: {
          minChunks: 2,
          priority: -20,
          reuseExistingChunk: true
        }
      }
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    }),
    new CleanWebpackPlugin(),
    new webpack.HashedModuleIdsPlugin(), // 缓存
  ]

};

const webpackConfigs = merge(webpackBaseConf,webpackProConf);
module.exports= webpackConfigs;

 

相关文章:

  • 2021-06-12
  • 2021-08-01
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-02-12
猜你喜欢
  • 2022-12-23
  • 2022-02-01
  • 2022-01-20
  • 2018-01-25
  • 2021-06-11
  • 2021-09-05
相关资源
相似解决方案