hackXlsx.ts 620 B

1234567891011121314151617
  1. import fs from 'fs-extra';
  2. import path from 'path';
  3. // Because xlsx internally references the node module, the pre-optimization of vite2.0 fails. Since the node module inside xlsx is not used on the web side, all the code that uses the node module is replaced with `{}` to be compatible with'vite2'
  4. function replaceCjs() {
  5. const xlsx = path.resolve(process.cwd(), 'node_modules/xlsx/xlsx.js');
  6. let raw = fs.readFileSync(xlsx, 'utf-8');
  7. raw = raw
  8. .replace(`require('fs')`, '{}')
  9. .replace(`require('stream')`, '{}')
  10. .replace(`require('crypto')`, '{}');
  11. fs.writeFileSync(xlsx, raw);
  12. }
  13. replaceCjs();