// Change theme plugin import MergeLessPlugin from 'antd-pro-merge-less'; import AntDesignThemePlugin from 'antd-theme-webpack-plugin'; import path from 'path'; const CompressionWebpackPlugin = require('compression-webpack-plugin'); const prodGzipList = ['js', 'css']; export default config => { config.module .rule() .test(/\.(pdf|svg|docx|doc)$/) .use('file-loader?name=[path][name].[ext]') .loader('file-loader') .end(); // pro 和 开发环境再添加这个插件 // if (process.env.APP_TYPE === 'site' || process.env.NODE_ENV !== 'production') { // // 将所有 less 合并为一个供 themePlugin使用 // const outFile = path.join(__dirname, '../.temp/ant-design-pro.less'); // const stylesDir = path.join(__dirname, '../src/'); // config.plugin('merge-less').use(MergeLessPlugin, [ // { // stylesDir, // outFile, // }, // ]); // config.plugin('ant-design-theme').use(AntDesignThemePlugin, [ // { // antDir: path.join(__dirname, '../node_modules/antd'), // stylesDir, // varFile: path.join(__dirname, '../node_modules/antd/lib/style/themes/default.less'), // mainLessFile: outFile, // themeVariables: ['@primary-color'], // indexFileName: 'index.html', // generateOne: true, // lessUrl: 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js', // }, // ]); // } if (process.env.APP_TYPE !== 'site' || process.env.NODE_ENV !== 'development') { config.merge({ optimization: { minimize: true, splitChunks: { chunks: 'async', // chunks(chunk) { // // exclude `my-excluded-chunk` // return chunk.name !== 'my-excluded-chunk'; // }, minSize: 20000, //生成块的最小大小(以字节为单位)1024字节=1KB。 minChunks: 1, //拆分前必须共享模块的最小块数。 maxInitialRequests: 30, //入口点的最大并行请求数。 automaticNameDelimiter: '.', cacheGroups: { vendor: { name: 'vendors', test: /^.*node_modules[\\/](?!ag-grid-|lodash|wangeditor|react-virtualized|rc-drawer|rc-time-picker|rc-tree|echarts|echarts-gl|xlsx|@ant-design|antd|ali-oss).*$/, priority: -10, enforce: true, }, virtualized: { name: 'virtualized', test: /[\\/]node_modules[\\/]react-virtualized/, priority: 10, }, antd: { name: 'antd', test: /[\\/]node_modules[\\/]antd[\\/]/, priority: 9, }, // antv: { // name: "@antv", // test: /[\\/]node_modules[\\/]@antv[\\/]/, // priority: 9, // }, echarts: { // 1.27MB name: 'echarts', test: /[\\/]node_modules[\\/](echarts|echarts-gl)[\\/]/, priority: 10, enforce: true, }, bizcharts: { name: 'bizcharts', test: /[\\/]node_modules[\\/]bizcharts[\\/]/, chunks: 'all', priority: 10, }, hlsJs: { name: 'hlsJs', test: /[\\/]node_modules[\\/]hls.js[\\/]/, chunks: 'all', priority: 10, }, // moment: { // name: "moment", // test: /[\\/]node_modules[\\/]moment[\\/]/, // chunks: "all", // priority: 10 // }, fileManage: { name: 'fileManage', test: /[\\/]node_modules[\\/]@opuscapita[\\/]/, chunks: 'all', priority: 10, }, pdfJs: { name: 'pdfjs-dist', test: /[\\/]node_modules[\\/]pdfjs-dist[\\/]/, chunks: 'all', priority: 10, }, ggEditor: { name: 'ggEditor', test: /[\\/]node_modules[\\/]gg-editor-core[\\/]/, chunks: 'all', priority: 10, }, // zrender: { // name: "zrender", // test: /[\\/]node_modules[\\/]zrender[\\/]/, // chunks: "all", // priority: 10 // }, swiper: { name: 'swiper', test: /[\\/]node_modules[\\/]swiper[\\/]/, chunks: 'all', priority: 10, }, flv: { name: 'flv', test: /[\\/]node_modules[\\/]flv.js[\\/]/, chunks: 'all', priority: 10, }, xlsx: { name: 'xlsx', test: /[\\/]node_modules[\\/]xlsx[\\/]/, chunks: 'async', priority: 10, }, // rctree: { // name: "rctree", // test: /[\\/]node_modules[\\/]rc-tree/, // chunks: "all", // priority: -1 // }, // rccalendar: { // name: "rccalendar", // test: /[\\/]node_modules[\\/]rc-calendar[\\/]/, // chunks: "all", // priority: -1 // }, wang: { name: 'wang', test: /[\\/]node_modules[\\/]wangeditor[\\/]/, chunks: 'all', priority: -1, }, // lodash: { // name: "lodash", // test: /[\\/]node_modules[\\/]lodash[\\/]/, // chunks: "all", // priority: -2 // }, // rcdrawer: { // name: "rcdrawer", // test: /[\\/]node_modules[\\/]rc-drawer/, // chunks: "all", // priority: 10 // }, ag: { name: 'ag', test: /[\\/]node_modules[\\/]ag-grid-/, chunks: 'all', priority: 10, }, }, }, }, }); } if (process.env.NODE_ENV === 'production') { // 生产模式开启 config.plugin('compression-webpack-plugin').use( new CompressionWebpackPlugin({ // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称 algorithm: 'gzip', // 指定生成gzip格式 test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩 threshold: 10240, //对超过10k的数据进行压缩 minRatio: 0.6, // 压缩比例,值为0 ~ 1 }) ); } //过滤掉momnet的那些不使用的国际化文件 config .plugin('replace') .use(require('webpack').ContextReplacementPlugin) .tap(() => { return [/moment[/\\]locale$/, /zh-cn/]; }); // config.output.filename = '[name].[contenthash].js' };