Skip to content

Commit d8120db

Browse files
committed
fix(react): use tsdown copy and watch plugin for css files
1 parent 88a3a2d commit d8120db

File tree

3 files changed

+27
-258
lines changed

3 files changed

+27
-258
lines changed

packages/react/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
}
3636
},
3737
"scripts": {
38-
"build": "tsdown && pnpm css:copy",
39-
"build:watch": "concurrently 'tsdown --watch ./src --no-clean' 'pnpm css:watch'",
40-
"css:copy": "rsync -a --include='*/' --include='*.css' --exclude='*' src/presets/ dist/default/presets/",
41-
"css:watch": "chokidar 'src/presets/**/*.css' --initial -c 'pnpm run css:copy'",
38+
"build": "tsdown",
39+
"build:watch": "tsdown --watch ./src --no-clean",
4240
"dev": "pnpm build:watch",
4341
"test": "vitest run",
4442
"test:watch": "vitest",
@@ -55,8 +53,6 @@
5553
"devDependencies": {
5654
"@testing-library/react": "^16.3.0",
5755
"@types/react": "^19.2.7",
58-
"chokidar-cli": "^3.0.0",
59-
"concurrently": "^9.2.1",
6056
"jsdom": "^26.1.0",
6157
"react": "^19.2.1",
6258
"react-dom": "^19.2.1",

packages/react/tsdown.config.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,8 @@ type BuildMode = 'dev' | 'default';
66

77
const buildModes: BuildMode[] = ['dev', 'default'];
88

9-
const presetsEntries = Object.fromEntries(
10-
globSync('src/presets/**/*.{ts,tsx}').map((file) => {
11-
const key = file.replace('src/', '').replace(/\.tsx?$/, '');
12-
return [key, file];
13-
})
14-
);
15-
16-
const createConfig = (mode: BuildMode): UserConfig => ({
17-
entry: {
18-
index: './src/index.ts',
19-
...presetsEntries,
20-
},
9+
const createConfig = (mode: BuildMode, isWatch: boolean): UserConfig => ({
10+
entry: 'src/**/index.ts',
2111
platform: 'browser',
2212
format: 'es',
2313
sourcemap: true,
@@ -32,6 +22,27 @@ const createConfig = (mode: BuildMode): UserConfig => ({
3222
__DEV__: mode === 'dev' ? 'true' : 'false',
3323
},
3424
dts: mode === 'dev',
25+
copy: [
26+
{
27+
from: 'src/**/*.css',
28+
to: `dist/${mode}`,
29+
flatten: false,
30+
},
31+
],
32+
plugins: [
33+
{
34+
name: 'watch-css',
35+
buildStart() {
36+
const cssFiles = globSync('src/**/*.css');
37+
for (const file of cssFiles) {
38+
this.addWatchFile(file);
39+
}
40+
},
41+
},
42+
],
3543
});
3644

37-
export default defineConfig(buildModes.map((mode) => createConfig(mode)));
45+
export default defineConfig((cliOptions) => {
46+
const isWatch = !!cliOptions.watch;
47+
return buildModes.map((mode) => createConfig(mode, isWatch));
48+
});

0 commit comments

Comments
 (0)