generateSizeLimit.js 955 Bytes
Newer Older
dengxiaofeng's avatar
dengxiaofeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
const path = require('path');
const fs = require('fs');
const writePkg = require('write-pkg');

const cwd = process.cwd();
const ignoreDirPath = ['.DS_Store'];

const filePath = path.resolve(cwd, 'package.json');
const packagesDir = path.resolve(cwd, 'packages');
const json = JSON.parse(fs.readFileSync(filePath, 'utf8'));

delete json['size-limit'];

let componentsNames = fs.readdirSync(packagesDir);

componentsNames = componentsNames.filter((dir) => ignoreDirPath.indexOf(dir) === -1);

(async () => {
  const sizeLimitConfig = [];
  componentsNames.forEach((component) => {
    sizeLimitConfig.push({
      path: `packages/${component}/lib/**/*.js`,
      limit: '2 s',
      webpack: false,
      running: false,
    });
    sizeLimitConfig.push({
      path: `packages/${component}/es/**/*.js`,
      limit: '2 s',
      webpack: false,
      running: false,
    });
  });

  await writePkg(cwd, { ...json, 'size-limit': sizeLimitConfig });
邓晓峰's avatar
邓晓峰 committed
36
})();