Skip to content

Commit 53a22eb

Browse files
authored
chore(examples/37_css-stylex): use @stylexjs/unplugin (#1983)
Vite 8 use lightningcss instead of postcss, so original approach will break. This PR is the preparation. This approach is also used by StyleX upstream: https://github.com/facebook/stylex/tree/main/examples/example-waku Split from #1982
1 parent 6dfbc99 commit 53a22eb

6 files changed

Lines changed: 103 additions & 784 deletions

File tree

examples/37_css-stylex/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
"waku": "1.0.0-alpha.5"
1717
},
1818
"devDependencies": {
19-
"@babel/plugin-syntax-jsx": "^7.28.6",
20-
"@babel/preset-typescript": "^7.28.5",
21-
"@stylexjs/postcss-plugin": "^0.17.5",
19+
"@stylexjs/unplugin": "^0.18.1",
2220
"@types/react": "^19.2.14",
2321
"@types/react-dom": "^19.2.3",
24-
"@vitejs/plugin-react": "^5.1.0",
25-
"vite-plugin-babel": "^1.5.1"
22+
"@vitejs/plugin-react": "^5.1.0"
2623
}
2724
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
5+
function DevStyleXInjectImpl() {
6+
useEffect(() => {
7+
// @ts-expect-error virtual module
8+
// eslint-disable-next-line import/no-unresolved
9+
void import('virtual:stylex:css-only');
10+
}, []);
11+
return <link rel="stylesheet" href="/virtual:stylex.css" />;
12+
}
13+
14+
export const DevStyleXInject = import.meta.env.DEV
15+
? DevStyleXInjectImpl
16+
: () => null;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
@stylex;

examples/37_css-stylex/src/pages/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '../index.css';
22
import * as stylex from '@stylexjs/stylex';
33
import { Counter } from '../components/counter';
4+
import { DevStyleXInject } from '../components/stylex-dev-injection';
45

56
const styles = stylex.create({
67
server: {
@@ -15,6 +16,7 @@ const styles = stylex.create({
1516
export default async function HomePage() {
1617
return (
1718
<div>
19+
<DevStyleXInject />
1820
<title>Waku</title>
1921
<div {...stylex.props(styles.server)}>Server Style (green)</div>
2022
<div>
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
// based on
22
// https://github.com/pawelblaszczyk5/vite-rsc-experiments/blob/4bc05095d9ec5dcb584af43a5704c4dceffd38b8/apps/stylex/vite.config.ts
33

4+
import stylex from '@stylexjs/unplugin/vite';
45
import react from '@vitejs/plugin-react';
56
import { defineConfig } from 'waku/config';
67

7-
const babelConfig = {
8-
plugins: [
9-
['@babel/plugin-syntax-jsx', {}],
10-
[
11-
'@stylexjs/babel-plugin',
12-
{
13-
treeshakeCompensation: true,
14-
unstable_moduleResolution: { type: 'commonJS' },
15-
},
16-
],
17-
],
18-
presets: ['@babel/preset-typescript'],
19-
};
20-
218
export default defineConfig({
229
vite: {
23-
plugins: [react({ babel: babelConfig })],
10+
plugins: [
11+
stylex({
12+
debug: process.env.NODE_ENV === 'development',
13+
treeshakeCompensation: true,
14+
useCSSLayers: true,
15+
devMode: 'css-only',
16+
runtimeInjection: false,
17+
}),
18+
react(),
19+
],
2420
},
2521
});

0 commit comments

Comments
 (0)