optimizer.ts 576 B

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