Skip to content

Commit

Permalink
fix(bundler-webpack): mini-css-extract-plugin with speed measure (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fz6m committed Dec 1, 2022
1 parent 12d57ef commit ae52dcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/bundler-webpack/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ export async function getConfig(opts: IOpts): Promise<Configuration> {
let webpackConfig = config.toConfig();

// speed measure
// TODO: mini-css-extract-plugin 报错
webpackConfig = await addSpeedMeasureWebpackPlugin({
webpackConfig,
});
Expand Down
11 changes: 11 additions & 0 deletions packages/bundler-webpack/src/config/speedMeasureWebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ interface IOpts {
export async function addSpeedMeasureWebpackPlugin(opts: IOpts) {
let webpackConfig = opts.webpackConfig;
if (process.env.SPEED_MEASURE) {
const miniCssExtractPluginIdx = webpackConfig.plugins?.findIndex(
(plugin) => plugin.constructor.name === 'MiniCssExtractPlugin',
);
const miniCssExtractPlugin =
webpackConfig.plugins?.[miniCssExtractPluginIdx!];

const smpOption =
process.env.SPEED_MEASURE === 'JSON'
? {
Expand All @@ -18,6 +24,11 @@ export async function addSpeedMeasureWebpackPlugin(opts: IOpts) {
}
: { outputFormat: 'human', outputTarget: console.log };
webpackConfig = new SpeedMeasurePlugin(smpOption).wrap(webpackConfig);

// https://github.com/stephencookdev/speed-measure-webpack-plugin/issues/167#issuecomment-1318684127
if (miniCssExtractPlugin) {
webpackConfig.plugins![miniCssExtractPluginIdx!] = miniCssExtractPlugin;
}
}
return webpackConfig;
}

0 comments on commit ae52dcd

Please sign in to comment.