Skip to content

Commit

Permalink
chore(rspack-provider): return compiler instead of multiCompiler when…
Browse files Browse the repository at this point in the history
… targets length is 1
  • Loading branch information
9aoy committed Nov 20, 2023
1 parent 50b24cd commit f1a8e96
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/quiet-coins-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/builder-rspack-provider': patch
---

chore(rspack-provider): return compiler instead of multiCompiler when targets length is 1

chore(rspack-provider): 返回 compiler 而非 multiCompiler 当 targets 长度为 1 时
36 changes: 24 additions & 12 deletions packages/builder/builder-rspack-provider/src/core/createCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TARGET_ID_MAP,
} from '@modern-js/builder-shared';
import type { Context, RspackConfig } from '../types';
import { Stats, MultiStats } from '@rspack/core';

export async function createCompiler({
context,
Expand All @@ -22,27 +23,38 @@ export async function createCompiler({
const { rspack } = await import('@rspack/core');
const { isDev } = await import('@modern-js/utils');

const compiler = rspack(rspackConfigs);
const compiler =
rspackConfigs.length === 1
? rspack(rspackConfigs[0])
: rspack(rspackConfigs);

let isFirstCompile = true;

compiler.hooks.done.tap('done', async stats => {
compiler.hooks.done.tap('done', async (stats: Stats | MultiStats) => {
const obj = stats.toJson({
all: false,
timings: true,
});

const printTime = (c: typeof obj, index: number) => {
if (c.time) {
const time = prettyTime(c.time / 1000);
const target = Array.isArray(context.target)
? context.target[index]
: context.target;
const name = TARGET_ID_MAP[target || 'web'];
logger.ready(`${name} compiled in ${time}`);
}
};

if (!stats.hasErrors()) {
obj.children?.forEach((c, index) => {
if (c.time) {
const time = prettyTime([0, c.time * 10 ** 6]);
const target = Array.isArray(context.target)
? context.target[index]
: context.target;
const name = TARGET_ID_MAP[target || 'web'];
logger.ready(`${name} compiled in ${time}`);
}
});
if (obj.children) {
obj.children.forEach((c, index) => {
printTime(c, index);
});
} else {
printTime(obj, 0);
}
}

const { message, level } = formatStats(stats);
Expand Down

0 comments on commit f1a8e96

Please sign in to comment.