optimizer.ts 604 B

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