speedMeasureWebpackPlugin.js 601 Bytes
Newer Older
邓晓峰's avatar
邓晓峰 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const { join } = require('path');
const SpeedMeasurePlugin = require('../compiled/speed-measure-webpack-plugin');
export async function addSpeedMeasureWebpackPlugin(opts) {
  let { webpackConfig } = opts;
  if (process.env.SPEED_MEASURE) {
    const smpOption =
      process.env.SPEED_MEASURE === 'JSON'
        ? {
            outputFormat: 'json',
            outputTarget: join(process.cwd(), 'SPEED_MEASURE.json'),
          }
        : { outputFormat: 'human', outputTarget: console.log };
    webpackConfig = new SpeedMeasurePlugin(smpOption).wrap(webpackConfig);
  }
  return webpackConfig;
}