-
Notifications
You must be signed in to change notification settings - Fork 424
[postcss-plugin] Implement custom importSources for React Strict DOM compatibility #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,15 @@ module.exports = function createBundler() { | |
| const styleXRulesMap = new Map(); | ||
|
|
||
| // Determines if the source code should be transformed based on the presence of StyleX imports. | ||
| function shouldTransform(sourceCode) { | ||
| return sourceCode.includes('stylex'); | ||
| function shouldTransform(sourceCode, options) { | ||
| const { importSources } = options; | ||
|
|
||
| return importSources.some((importSource) => { | ||
| if (typeof importSource === 'string') { | ||
| return sourceCode.includes(importSource); | ||
| } | ||
| return importSource.includes(sourceCode.from); | ||
| }); | ||
| } | ||
|
|
||
| // Transforms the source code using Babel, extracting StyleX rules and storing them. | ||
|
|
@@ -25,6 +32,7 @@ module.exports = function createBundler() { | |
| filename: id, | ||
| caller: { | ||
| name: '@stylexjs/postcss-plugin', | ||
| platform: 'web', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://facebook.github.io/react-strict-dom/learn/setup/#babel-configuration |
||
| isDev, | ||
| }, | ||
| ...babelConfig, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ const plugin = ({ | |
| include, | ||
| exclude, | ||
| useCSSLayers = false, | ||
| importSources = ['@stylexjs/stylex', 'stylex'], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly speaking, we only need If we're okay with breaking some backward compatibility, we can just use |
||
| }) => { | ||
| exclude = [ | ||
| // Exclude type declaration files by default because it never contains any CSS rules. | ||
|
|
@@ -49,6 +50,7 @@ const plugin = ({ | |
| cwd, | ||
| babelConfig, | ||
| useCSSLayers, | ||
| importSources, | ||
| isDev, | ||
| }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.