plugin.config.js 2.66 KB
Newer Older
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
1 2
// Change theme plugin

3
import MergeLessPlugin from 'antd-pro-merge-less';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
4
import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
5
import path from 'path';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
6

Zhongjie Wu's avatar
Zhongjie Wu committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
function getModulePackageName(module) {
  if (!module.context) return null;

  const nodeModulesPath = path.join(__dirname, '../node_modules/');
  if (module.context.substring(0, nodeModulesPath.length) !== nodeModulesPath) {
    return null;
  }

  const moduleRelativePath = module.context.substring(nodeModulesPath.length);
  const [moduleDirName] = moduleRelativePath.split(path.sep);
  let packageName = moduleDirName;
  // handle tree shaking
  if (packageName.match('^_')) {
    // eslint-disable-next-line prefer-destructuring
    packageName = packageName.match(/^_(@?[^@]+)/)[1];
  }
  return packageName;
}

26
export default config => {
27 28 29 30 31
  // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
  if (
    process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ||
    process.env.NODE_ENV !== 'production'
  ) {
32 33 34
    // ๅฐ†ๆ‰€ๆœ‰ less ๅˆๅนถไธบไธ€ไธชไพ› themePluginไฝฟ็”จ
    const outFile = path.join(__dirname, '../.temp/ant-design-pro.less');
    const stylesDir = path.join(__dirname, '../src/');
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
35

36 37 38 39 40 41
    config.plugin('merge-less').use(MergeLessPlugin, [
      {
        stylesDir,
        outFile,
      },
    ]);
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
42

43 44 45 46 47 48 49 50 51 52 53 54
    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',
      },
    ]);
  }
Zhongjie Wu's avatar
Zhongjie Wu committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  // optimize chunks
  config.optimization
    .runtimeChunk(false) // share the same chunks across different modules
    .splitChunks({
      chunks: 'async',
      name: 'vendors',
      maxInitialRequests: Infinity,
      minSize: 0,
      cacheGroups: {
        vendors: {
          test: module => {
            const packageName = getModulePackageName(module);
            if (packageName) {
              return ['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0;
            }
            return false;
          },
          name(module) {
            const packageName = getModulePackageName(module);

            if (['bizcharts', '@antv_data-set'].indexOf(packageName) >= 0) {
              return 'viz'; // visualization package
            }
            return 'misc';
          },
        },
      },
    });
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
83
};