• webpack code splitting


    一、代码分割优化

    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;
  • 相关阅读:
    day4-生成器
    第三天-函数
    编码问题
    可变不可变类型总结
    由var与let引起的百度地图所有的覆盖点的信息都是最后一个的
    《企业应用架构模式》 三
    IndexDB
    ESA与SOA
    SOA
    Dubbo(一)
  • 原文地址:https://www.cnblogs.com/shangyueyue/p/10754580.html
Copyright © 2020-2023  润新知