Skip to content

Commit 08e5731

Browse files
committed
Add react-strict-dom/postcss-plugin
1 parent 4fac83c commit 08e5731

6 files changed

Lines changed: 60 additions & 22 deletions

File tree

apps/examples/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"expo": "^52.0.6",
1515
"expo-build-properties": "~0.13.1",
1616
"expo-status-bar": "~2.0.0",
17-
"postcss-react-strict-dom": "^0.0.5",
1817
"react": "~18.3.1",
1918
"react-dom": "~18.3.1",
2019
"react-native": "~0.76.1",

apps/examples/postcss.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
*/
77

88
module.exports = {
9-
plugins: {
10-
'postcss-react-strict-dom': {
9+
plugins: [
10+
require('react-strict-dom/postcss-plugin')({
1111
include: ['src/**/*.{js,jsx,mjs,ts,tsx}']
12-
},
13-
autoprefixer: {}
14-
}
12+
}),
13+
require('autoprefixer')
14+
]
1515
};

apps/website/docs/learn/01-installation.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ For web support, please make sure the following peer dependencies are installed:
2222
npm install react react-dom
2323
```
2424

25-
Extracting styles to static CSS requires the following PostCSS plugin:
26-
27-
```
28-
npm install --save-dev postcss-react-strict-dom
29-
```
30-
3125
### Native
3226

3327
For native support, please make sure the following peer dependencies are installed (note that using the new React Native architecture is required):

apps/website/docs/learn/02-environment-setup.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,35 @@ module.exports = function (api) {
4747
// Expo's babel preset
4848
'babel-preset-expo',
4949
// React Strict DOM's babel preset
50-
[reactStrictPreset, {
51-
debug: dev,
52-
dev,
53-
platform
54-
}]
50+
[
51+
reactStrictPreset,
52+
{
53+
debug: dev,
54+
dev,
55+
platform
56+
}
57+
]
5558
]
5659
};
5760
};
5861
```
5962
6063
## PostCSS configuration
6164
62-
[PostCSS](https://postcss.org/) is a tool for generating CSS. It's enabled by default in Expo and it's the recommended way to extract React Strict DOM styles to static CSS for web builds. Once the [postcss-react-strict-dom](https://github.com/javascripter/postcss-react-strict-dom) plugin is installed, it can be used to extract styles. Create a `postcss.config.js` file as follows.
65+
[PostCSS](https://postcss.org/) is a tool for generating CSS. It's enabled by default in Expo and it's the recommended way to extract React Strict DOM styles to static CSS for web builds. `react-strict-dom/postcss-plugin` can be used to extract styles. Create a `postcss.config.js` file as follows.
6366
6467
```js title="postcss.config.js"
6568
module.exports = {
6669
plugins: {
67-
'postcss-react-strict-dom': {
70+
require('react-strict-dom/postcss-plugin')({
6871
include: [
6972
// Include source files to watch for style changes
7073
'src/**/*.{js,jsx,mjs,ts,tsx}',
7174
// List any installed node_modules that include UI built with React Strict DOM
7275
'node_modules/<package-name>/*.js'
7376
]
74-
},
75-
autoprefixer: {}
77+
}),
78+
require('autoprefixer')
7679
}
7780
};
7881
```
@@ -122,7 +125,6 @@ Your app needs to include a CSS file that contains a `@stylex` directive. This a
122125
123126
Next, import the CSS file in the entry file of your app.
124127
125-
126128
```js title="index.js"
127129
// Required for CSS to work on Expo Web.
128130
import './stylex.css';

packages/react-strict-dom/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
},
1616
"./babel-preset": "./babel/preset.js",
17+
"./postcss-plugin": "./postcss/plugin.js",
1718
"./runtime": "./dist/dom/runtime.js",
1819
"./package.json": "./package.json"
1920
},
@@ -35,6 +36,7 @@
3536
"dependencies": {
3637
"@babel/helper-module-imports": "^7.24.7",
3738
"@stylexjs/babel-plugin": "^0.9.3",
39+
"@stylexjs/postcss-plugin": "^0.9.3",
3840
"@stylexjs/stylex": "^0.9.3",
3941
"postcss-value-parser": "^4.1.0"
4042
},
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*
8+
*/
9+
10+
const styleXPlugin = require('@stylexjs/postcss-plugin');
11+
12+
const plugin = ({
13+
cwd = process.cwd(),
14+
// By default reuses the Babel configuration from the project root.
15+
// Use `babelrc: false` to disable this behavior.
16+
babelConfig = {},
17+
include,
18+
exclude
19+
}) => {
20+
include = [
21+
// Include the React Strict DOM package's source files by default
22+
require.resolve('react-strict-dom'),
23+
...(include ?? [])
24+
];
25+
26+
return styleXPlugin({
27+
cwd,
28+
babelConfig,
29+
include,
30+
exclude,
31+
useCSSLayers: false,
32+
importSources: [
33+
'@stylexjs/stylex',
34+
[{ from: 'react-strict-dom', as: 'css' }]
35+
]
36+
});
37+
};
38+
39+
plugin.postcss = true;
40+
41+
module.exports = plugin;

0 commit comments

Comments
 (0)