Skip to content

Commit 49e62f6

Browse files
authored
fix: failed to load postcss.config.ts (#2385)
1 parent 2b81dd2 commit 49e62f6

File tree

8 files changed

+57
-5
lines changed

8 files changed

+57
-5
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { build } from '@e2e/helper';
2+
import { expect, test } from '@playwright/test';
3+
4+
test('should load postcss.config.ts correctly', async () => {
5+
const rsbuild = await build({
6+
cwd: __dirname,
7+
});
8+
9+
const files = await rsbuild.unwrapOutputJSON();
10+
const indexCssFile = Object.keys(files).find(
11+
(file) => file.includes('index.') && file.endsWith('.css'),
12+
)!;
13+
14+
expect(files[indexCssFile]).toEqual(
15+
'.text-3xl{font-size:1.875rem;line-height:2.25rem}.font-bold{font-weight:700}.underline{text-decoration-line:underline}',
16+
);
17+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const path = require('node:path');
2+
3+
export default {
4+
plugins: {
5+
tailwindcss: {
6+
config: path.join(__dirname, './tailwind.config.cjs'),
7+
},
8+
},
9+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
html: {
3+
template: './src/index.html',
4+
},
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@tailwind utilities;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!doctype html>
2+
<html>
3+
<head></head>
4+
<body>
5+
<h1 class="text-3xl font-bold underline">Hello world!</h1>
6+
</body>
7+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './index.css';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('node:path');
2+
3+
/** @type {import('tailwindcss').Config} */
4+
module.exports = {
5+
content: [path.join(__dirname, './src/**/*.{html,js,ts,jsx,tsx}')],
6+
theme: {
7+
extend: {},
8+
},
9+
plugins: [],
10+
};

packages/core/prebundle.config.mjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,24 @@ export default {
105105
{
106106
name: 'postcss-load-config',
107107
externals: {
108-
jiti: '@rsbuild/shared/jiti',
109108
yaml: '@rsbuild/shared/yaml',
109+
'@rsbuild/shared/jiti': '@rsbuild/shared/jiti',
110110
},
111111
ignoreDts: true,
112112
// this is a trick to avoid ncc compiling the dynamic import syntax
113113
// https://github.com/vercel/ncc/issues/935
114114
beforeBundle(task) {
115-
replaceFileContent(
116-
join(task.depPath, 'src/req.js'),
117-
(content) => `${content.replace('await import', 'await __import')}`,
115+
replaceFileContent(join(task.depPath, 'src/req.js'), (content) =>
116+
content
117+
.replaceAll('await import', 'await __import')
118+
.replaceAll(`import('jiti')`, `import('@rsbuild/shared/jiti')`),
118119
);
119120
},
120121
afterBundle(task) {
121122
replaceFileContent(
122123
join(task.distPath, 'index.js'),
123-
(content) => `${content.replace('await __import', 'await import')}`,
124+
(content) =>
125+
`${content.replaceAll('await __import', 'await import')}`,
124126
);
125127
},
126128
},

0 commit comments

Comments
 (0)