Skip to content

Commit c92d58c

Browse files
committed
perf(cli): lazy-load setup and staged commands
1 parent 1e9c01c commit c92d58c

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎packages/rstack/rslib.config.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig } from '@rslib/core';
22
import pkgJson from './package.json' with { type: 'json' };
33

4-
const fullyMinifiedChunks = /lintStaged\.js$/;
4+
const fullyMinifiedChunks = /staged\.js$/;
55

66
export default defineConfig({
77
lib: [{ syntax: 'es2023', dts: true }],
@@ -32,7 +32,8 @@ export default defineConfig({
3232
css: false,
3333
jsOptions: [
3434
{
35-
// Fully minify the bundled lint-staged code to reduce package size.
35+
// Fully minify the staged chunk, including bundled lint-staged code,
36+
// to reduce package size.
3637
include: fullyMinifiedChunks,
3738
},
3839
{

‎packages/rstack/src/cli/commands.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { join } from 'node:path';
22
import { color } from 'rslog';
33
import { getConfigState } from '../config.ts';
4-
import { runSetupCLI } from '../setup/index.ts';
5-
import { runStagedCLI } from '../staged.ts';
64
import { insertConfigArg, parseCliArgs } from './args.ts';
75

86
declare global {
@@ -154,11 +152,19 @@ export async function setupCommands(): Promise<void> {
154152
}
155153

156154
if (command === 'staged') {
155+
const { runStagedCLI } = await import(
156+
/* rspackChunkName: 'staged' */
157+
'../staged.ts'
158+
);
157159
await runStagedCLI(args.slice(1));
158160
return;
159161
}
160162

161163
if (command === 'setup') {
164+
const { runSetupCLI } = await import(
165+
/* rspackChunkName: 'setup' */
166+
'../setup/index.ts'
167+
);
162168
runSetupCLI(args.slice(1));
163169
return;
164170
}

‎packages/rstack/src/staged.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { parseArgs } from 'node:util';
2+
import lintStaged from 'lint-staged';
23
import { color } from 'rslog';
34
import { loadRstackConfig } from './config.ts';
45

@@ -70,10 +71,6 @@ export async function runStagedCLI(args: string[]): Promise<void> {
7071
);
7172
}
7273

73-
const { default: lintStaged } = await import(
74-
/* rspackChunkName: 'lintStaged' */
75-
'lint-staged'
76-
);
7774
const success = await lintStaged({
7875
allowEmpty: values['allow-empty'] ?? values.allowEmpty,
7976
concurrent: values.concurrent === undefined ? undefined : JSON.parse(values.concurrent),

0 commit comments

Comments
 (0)