Skip to content

Commit aeaf6ae

Browse files
authored
feat: support zero-configuration (#5)
If no `tailwind.config.js` is provided, we will create a empty configuration with only `content` that contains all the modules in the module graph. This should allow using this plugin with zero-configuration.
1 parent 2bce99c commit aeaf6ae

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/TailwindCSSRspackPlugin.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs';
12
import { mkdtemp, writeFile } from 'node:fs/promises';
23
import { tmpdir } from 'node:os';
34
import path from 'node:path';
@@ -196,13 +197,20 @@ class TailwindRspackPluginImpl {
196197

197198
const configPath = path.resolve(outputDir, 'tailwind.config.mjs');
198199

200+
const content = JSON.stringify(Array.from(entryModules));
201+
199202
await writeFile(
200203
configPath,
201-
`\
204+
existsSync(userConfig)
205+
? `\
202206
import config from '${pathToFileURL(userConfig)}'
203207
export default {
204208
...config,
205-
content: ${JSON.stringify(Array.from(entryModules))}
209+
content: ${content}
210+
}`
211+
: `\
212+
export default {
213+
content: ${content}
206214
}`,
207215
);
208216

test/config/index.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,31 @@ test('should build with absolute config', async ({ page }) => {
6969

7070
await server.close();
7171
});
72+
73+
test('should build without tailwind.config.js', async ({ page }) => {
74+
const rsbuild = await createRsbuild({
75+
cwd: __dirname,
76+
rsbuildConfig: {
77+
plugins: [pluginTailwindCSS()],
78+
},
79+
});
80+
81+
await rsbuild.build();
82+
const { server, urls } = await rsbuild.preview();
83+
84+
await page.goto(urls[0]);
85+
86+
const display = await page.evaluate(() => {
87+
const el = document.getElementById('test');
88+
89+
if (!el) {
90+
throw new Error('#test not found');
91+
}
92+
93+
return window.getComputedStyle(el).getPropertyValue('display');
94+
});
95+
96+
expect(display).toBe('flex');
97+
98+
await server.close();
99+
});

0 commit comments

Comments
 (0)