-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
37 lines (32 loc) · 960 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { RsbuildPlugin } from '@rsbuild/core';
import { resolvePackage } from '@rsbuild/shared';
import { startServer } from './server/server';
import { getRandomPort } from 'get-port-please';
export const pluginConsoleDebug = (): RsbuildPlugin => {
return {
name: 'rsbuild-plugin-console-debug',
async setup(api) {
if (
api.context.bundlerType === 'webpack' ||
process.env.NODE_ENV !== 'development'
) {
return;
}
const port = await getRandomPort();
api.onAfterStartDevServer(async () => {
startServer(port);
});
api.modifyBundlerChain(async (chain, utils) => {
chain.module
.rule(utils.CHAIN_ID.RULE.TS)
.test(/\.(tsx|ts)$/i)
.use(utils.CHAIN_ID.RULE.TS)
.loader(resolvePackage('./core/applyConsoleDebug.js', __dirname))
.options({
port,
})
.end();
});
},
};
};