vben
2021-01-09 99ac309fa9eed36f8444b8bbab7b18275c5aa5aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { GetManualChunk, GetManualChunkApi } from 'rollup';
 
//
const vendorLibs: { match: string[]; output: string }[] = [
  {
    match: ['xlsx'],
    output: 'xlsx',
  },
];
 
// @ts-ignore
export const configManualChunk: GetManualChunk = (id: string, api: GetManualChunkApi) => {
  if (/[\\/]node_modules[\\/]/.test(id)) {
    const matchItem = vendorLibs.find((item) => {
      const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig');
      return reg.test(id);
    });
    return matchItem ? matchItem.output : null;
  }
};