Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
analyzerPort: process.env.ANALYZE_PORT || 8888,
openAnalyzer: process.env.ANALYZE_OPEN !== 'none',
// generate stats file while ANALYZE_DUMP exist
generateStatsFile: !!process.env.ANALYZE_DUMP,
statsFilename: process.env.ANALYZE_DUMP || 'stats.json',
logLevel: process.env.ANALYZE_LOG_LEVEL || 'info',
defaultSizes: 'parsed', // stat // gzip
},
]);
}
// plugins -> analyze report
if (process.env.ANALYZE_REPORT) {
webpackConfig
.plugin('bundle-analyzer-reporter')
.use(require('umi-webpack-bundle-analyzer').BundleAnalyzerPlugin, [
{
analyzerMode: 'disabled', // 关闭 analyzer server
generateReportFile: true, // 开启报告生成功能
reportDepth: 2, // 裁剪深度 2
reportDir: process.cwd(),
statsFilename: process.env.ANALYZE_DUMP || 'bundlestats.json', // 默认生成到 bundlestats.json
},
]);
}
if (process.env.DUPLICATE_CHECKER) {
webpackConfig
.plugin('duplicate-package-checker')
.use(require('duplicate-package-checker-webpack-plugin'));
}
export function parseChartData(stats) {
if (!stats) {
return null;
}
let chartData;
const analyzer = require('umi-webpack-bundle-analyzer/lib/analyzer');
try {
/**
* outputPath:
* 1. build: stats.outputPath
* 2. dev: null
*/
chartData = analyzer.getViewerData(stats, stats.outputPath, {
excludeAssets: null,
});
} catch (err) {
chartData = null;
}
if (isPlainObject(chartData) && isEmpty(chartData)) {
chartData = null;
}
return chartData;
}