Skip to content

Commit 2bce99c

Browse files
authored
fix: do not generate tailwind.config.js in dist/ (#4)
* fix: do not generate `tailwind.config.js` in dist/ * fix: tmpdir
1 parent 961f079 commit 2bce99c

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/TailwindCSSRspackPlugin.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { mkdir, writeFile } from 'node:fs/promises';
1+
import { mkdtemp, writeFile } from 'node:fs/promises';
2+
import { tmpdir } from 'node:os';
23
import path from 'node:path';
34
import { pathToFileURL } from 'node:url';
45

@@ -184,13 +185,14 @@ class TailwindRspackPluginImpl {
184185
: // biome-ignore lint/style/noNonNullAssertion: should have context
185186
path.resolve(this.compiler.options.context!, this.options.config);
186187

187-
const outputDir = path.resolve(
188-
// biome-ignore lint/style/noNonNullAssertion: should have `output.path`
189-
this.compiler.options.output.path!,
190-
'.rsbuild',
191-
entryName,
192-
);
193-
await mkdir(outputDir, { recursive: true });
188+
const outputDir = DEBUG
189+
? path.resolve(
190+
// biome-ignore lint/style/noNonNullAssertion: should have `output.path`
191+
this.compiler.options.output.path!,
192+
'.rsbuild',
193+
entryName,
194+
)
195+
: await mkdtemp(path.join(tmpdir(), entryName));
194196

195197
const configPath = path.resolve(outputDir, 'tailwind.config.mjs');
196198

@@ -220,3 +222,14 @@ function collectModules(
220222
entryModules.add(module.resource);
221223
}
222224
}
225+
226+
const DEBUG = (function isDebug() {
227+
if (!process.env.DEBUG) {
228+
return false;
229+
}
230+
231+
const values = process.env.DEBUG.toLocaleLowerCase().split(',');
232+
return ['rsbuild', 'rsbuild:tailwind', 'rsbuild:*', '*'].some((key) =>
233+
values.includes(key),
234+
);
235+
})();

test/basic/index.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { dirname } from 'node:path';
1+
import { existsSync } from 'node:fs';
2+
import { dirname, resolve } from 'node:path';
23
import { fileURLToPath } from 'node:url';
34
import { expect, test } from '@playwright/test';
45
import { createRsbuild } from '@rsbuild/core';
@@ -64,3 +65,16 @@ test('should build with tailwind utilities', async ({ page }) => {
6465

6566
await server.close();
6667
});
68+
69+
test('should not generate tailwind.config.js in dist/', async () => {
70+
const rsbuild = await createRsbuild({
71+
cwd: __dirname,
72+
rsbuildConfig: {
73+
plugins: [pluginTailwindCSS()],
74+
},
75+
});
76+
77+
await rsbuild.build();
78+
79+
expect(existsSync(resolve(__dirname, './dist/.rsbuild'))).toBeFalsy();
80+
});

0 commit comments

Comments
 (0)