Skip to content

Commit 261dd86

Browse files
committed
fix: Windows path
1 parent 57d835b commit 261dd86

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

src/TailwindCSSRspackPlugin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mkdir, writeFile } from 'node:fs/promises';
22
import path from 'node:path';
3+
import { pathToFileURL } from 'node:url';
34

45
import type { Rspack } from '@rsbuild/core';
56

@@ -196,7 +197,7 @@ class TailwindRspackPluginImpl {
196197
await writeFile(
197198
configPath,
198199
`\
199-
import config from '${userConfig}'
200+
import config from '${pathToFileURL(userConfig)}'
200201
export default {
201202
...config,
202203
content: ${JSON.stringify(Array.from(entryModules))}

test/config/config/tailwind.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** @type {import('tailwindcss').Config} */
2+
export default {};

test/config/index.test.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { dirname, resolve } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { expect, test } from '@playwright/test';
4+
import { createRsbuild } from '@rsbuild/core';
5+
import { pluginTailwindCSS } from '../../src';
6+
7+
const __dirname = dirname(fileURLToPath(import.meta.url));
8+
9+
test('should build with relative config', async ({ page }) => {
10+
const rsbuild = await createRsbuild({
11+
cwd: __dirname,
12+
rsbuildConfig: {
13+
plugins: [
14+
pluginTailwindCSS({
15+
config: './config/tailwind.config.js',
16+
}),
17+
],
18+
},
19+
});
20+
21+
await rsbuild.build();
22+
const { server, urls } = await rsbuild.preview();
23+
24+
await page.goto(urls[0]);
25+
26+
const display = await page.evaluate(() => {
27+
const el = document.getElementById('test');
28+
29+
if (!el) {
30+
throw new Error('#test not found');
31+
}
32+
33+
return window.getComputedStyle(el).getPropertyValue('display');
34+
});
35+
36+
expect(display).toBe('flex');
37+
38+
await server.close();
39+
});
40+
41+
test('should build with absolute config', async ({ page }) => {
42+
const rsbuild = await createRsbuild({
43+
cwd: __dirname,
44+
rsbuildConfig: {
45+
plugins: [
46+
pluginTailwindCSS({
47+
config: resolve(__dirname, './config/tailwind.config.js'),
48+
}),
49+
],
50+
},
51+
});
52+
53+
await rsbuild.build();
54+
const { server, urls } = await rsbuild.preview();
55+
56+
await page.goto(urls[0]);
57+
58+
const display = await page.evaluate(() => {
59+
const el = document.getElementById('test');
60+
61+
if (!el) {
62+
throw new Error('#test not found');
63+
}
64+
65+
return window.getComputedStyle(el).getPropertyValue('display');
66+
});
67+
68+
expect(display).toBe('flex');
69+
70+
await server.close();
71+
});

test/config/src/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'tailwindcss/utilities.css';
2+
3+
function className() {
4+
return 'flex';
5+
}
6+
7+
const root = document.getElementById('root');
8+
const element = document.createElement('div');
9+
element.id = 'test';
10+
element.className = className();
11+
root.appendChild(element);

0 commit comments

Comments
 (0)