Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
defineConfig as defineRsbuildConfig,
loadConfig as loadRsbuildConfig,
mergeRsbuildConfig,
logger as rsbuildLogger,
rspack,
} from '@rsbuild/core';
import { glob } from 'tinyglobby';
Expand Down Expand Up @@ -81,6 +82,15 @@ import {
} from './utils/syntax';
import { loadTsconfig } from './utils/tsconfig';

rsbuildLogger.override({
start: (message) => {
Copy link
Member

@chenjiahan chenjiahan Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding logger.start is not a good idea, how about using a hook like onBeforeBuild

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot guarantee that logger.start will not be called from somewhere else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried onBeforeBuild before, but when multiple environments presents. It will be called multiple times. I think I should re-implement something like Building... with Rspack watchRun and done hook in Rslib side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onBeforeBuild is a global hook, are you registering plugins in global?

Copy link
Member Author

@fi3ework fi3ework Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onBeforeBuild is a global hook, are you registering plugins in global?

Yes. 🤡

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chenjiahan 🤔 Does Rsbuild interest in embed this clear so Rslib can inherit? The usage are same. It's better to align with Rsbuild.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rsbuild will not clear the logs before rebuilding, as this will likely cause useful logs to be cleared and make troubleshooting more difficult.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to give a try on Rslib, hoping it fit with the simpler lib scenario. 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, Rsbuild early versions will clear the log by default, but we later found that this caused more trouble than benefit, so we canceled it. However, for Rslib scenarios it is still worth a try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find an elegant way to archive this, I'm heading to close for now.

  • onBeforeBuild will run after Building... and clear it, so it's not an option.
  • watchRun is good, but can't find a way to register the plugin for only once. Register to the first environment only is also an ugly workaround.

// Soft clear, copied from https://github.com/lukeed/console-clear/blob/master/index.js.
// "start" callback will only be called on watch mode (first compile not included).
process.stdout.write('\x1B[H\x1B[2J');
logger.start(message);
},
});

/**
* This function helps you to autocomplete configuration types.
* It accepts a Rslib config object, or a function that returns a config.
Expand Down
Loading