Skip to content
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
1 change: 0 additions & 1 deletion apps/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"expo": "^53.0.11",
"expo-build-properties": "~0.14.6",
"expo-status-bar": "~2.2.3",
"postcss-react-strict-dom": "^0.0.5",
"react": "~19.0.0",
"react-dom": "~19.0.0",
"react-native": "~0.79.5",
Expand Down
13 changes: 6 additions & 7 deletions apps/examples/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/

module.exports = {
plugins: {
'postcss-react-strict-dom': {
include: ['src/**/*.{js,jsx,mjs,ts,tsx}'],
useLayers: true
},
autoprefixer: {}
}
plugins: [
require('react-strict-dom/postcss-plugin')({
include: ['src/**/*.{js,jsx,mjs,ts,tsx}']
}),
require('autoprefixer')
]
};
6 changes: 0 additions & 6 deletions apps/website/docs/learn/01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ For web support, please make sure the following peer dependencies are installed:
npm install react react-dom
```

Extracting styles to static CSS requires the following PostCSS plugin:

```
npm install --save-dev postcss-react-strict-dom
```

### Native

For native support, please make sure the following peer dependencies are installed.
Expand Down
22 changes: 12 additions & 10 deletions apps/website/docs/learn/02-environment-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,35 @@ module.exports = function (api) {
// Expo's babel preset
'babel-preset-expo',
// React Strict DOM's babel preset
[reactStrictPreset, {
debug: dev,
dev,
platform
}]
[
reactStrictPreset,
{
debug: dev,
dev,
platform
}
]
]
};
};
```

## PostCSS configuration

[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.
[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.

```js title="postcss.config.js"
module.exports = {
plugins: {
'postcss-react-strict-dom': {
require('react-strict-dom/postcss-plugin')({
include: [
// Include source files to watch for style changes
'src/**/*.{js,jsx,mjs,ts,tsx}',
// List any installed node_modules that include UI built with React Strict DOM
'node_modules/<package-name>/*.js'
]
},
autoprefixer: {}
}),
require('autoprefixer')
}
};
```
Expand Down Expand Up @@ -120,7 +123,6 @@ Your app needs to include a CSS file that contains a `@stylex` directive. This a

Next, import the CSS file in the entry file of your app.


```js title="index.js"
// Required for CSS to work on Expo Web.
import './stylex.css';
Expand Down
76 changes: 36 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/react-strict-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
},
"./babel-preset": "./babel/preset.js",
"./postcss-plugin": "./postcss/plugin.js",
"./runtime": "./dist/dom/runtime.js",
"./package.json": "./package.json"
},
Expand All @@ -34,8 +35,9 @@
},
"dependencies": {
"@babel/helper-module-imports": "^7.24.7",
"@stylexjs/babel-plugin": "^0.13.1",
"@stylexjs/stylex": "^0.13.1",
"@stylexjs/babel-plugin": "^0.14.1",
"@stylexjs/stylex": "^0.14.1",
"@stylexjs/postcss-plugin": "^0.14.1",
"postcss-value-parser": "^4.1.0"
},
"devDependencies": {
Expand Down
41 changes: 41 additions & 0 deletions packages/react-strict-dom/postcss/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const styleXPlugin = require('@stylexjs/postcss-plugin');

const plugin = ({
cwd = process.cwd(),
// By default reuses the Babel configuration from the project root.
// Use `babelrc: false` to disable this behavior.
babelConfig = {},
include,
exclude
}) => {
include = [
// Include the React Strict DOM package's source files by default
require.resolve('react-strict-dom'),
Comment thread
javascripter marked this conversation as resolved.
require.resolve('react-strict-dom/runtime'),
...(include ?? [])
];

return styleXPlugin({
cwd,
babelConfig,
include,
exclude,
useCSSLayers: true,
importSources: [
'@stylexjs/stylex',
'stylex',
{ from: 'react-strict-dom', as: 'css' }
]
});
};

plugin.postcss = true;

module.exports = plugin;