Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support zero-configuration #5

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/TailwindCSSRspackPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from 'node:fs';
import { mkdtemp, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
Expand Down Expand Up @@ -196,13 +197,20 @@ class TailwindRspackPluginImpl {

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

const content = JSON.stringify(Array.from(entryModules));

await writeFile(
configPath,
`\
existsSync(userConfig)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw an error when the userConfig is not the default path.

? `\
import config from '${pathToFileURL(userConfig)}'
export default {
...config,
content: ${JSON.stringify(Array.from(entryModules))}
content: ${content}
}`
: `\
export default {
content: ${content}
}`,
);

Expand Down
28 changes: 28 additions & 0 deletions test/config/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@ test('should build with absolute config', async ({ page }) => {

await server.close();
});

test('should build without tailwind.config.js', async ({ page }) => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [pluginTailwindCSS()],
},
});

await rsbuild.build();
const { server, urls } = await rsbuild.preview();

await page.goto(urls[0]);

const display = await page.evaluate(() => {
const el = document.getElementById('test');

if (!el) {
throw new Error('#test not found');
}

return window.getComputedStyle(el).getPropertyValue('display');
});

expect(display).toBe('flex');

await server.close();
});