-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add getModules function to make transpiling easier with Next.js.
#2696
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // This defines a function called `getModules` that can get an array of all | ||
| // React Spectrum modules. | ||
| // | ||
| // One use case for this function is it can be used to wrap the Next.js | ||
| // configuration in `next.config.js` so that React Spectrum works in Next.js | ||
| // without any errors. | ||
| // | ||
| // You can do something like this in your `next.config.js`: | ||
| // | ||
| // <next.config.js> | ||
| // | ||
| // const nextTranspileModules = require("next-transpile-modules"); | ||
| // const getReactSpectrumModules = require("react-spectrum-monorepo/lib/getModules"); | ||
| // | ||
| // // This wraps the Next.js configuration to do some transpilations so that React | ||
| // // Spectrum works in Next.js without any errors. | ||
| // // | ||
| // // Inspired by https://react-spectrum.adobe.com/react-spectrum/ssr.html#nextjs | ||
| // // | ||
| // const withTM = nextTranspileModules(getReactSpectrumModules()); | ||
| // | ||
| // module.exports = withTM({ | ||
| // // Your Next.js configuration | ||
| // }); | ||
| // | ||
| // </next.config.js> | ||
|
|
||
| const fs = require("fs"); | ||
|
|
||
| const flatten = (arr) => arr.reduce((acc, val) => acc.concat(val)); | ||
|
|
||
| const getModules = () => | ||
| flatten( | ||
| // Returns something like [ | ||
| // '@adobe/react-spectrum', | ||
| // '@adobe/react-spectrum-ui', | ||
| // '@adobe/react-spectrum-workflow', | ||
| // '@react-spectrum/actiongroup', | ||
| // '@react-spectrum/breadcrumbs', | ||
| // '@react-spectrum/button', | ||
| // ... | ||
| // '@spectrum-icons/ui', | ||
| // '@spectrum-icons/workflow' | ||
| // ] | ||
| ["@adobe", "@react-spectrum", "@spectrum-icons"].map((ns) => | ||
| fs.readdirSync(`./node_modules/${ns}`).map((dir) => `${ns}/${dir}`) | ||
| ) | ||
| ); | ||
|
|
||
| module.exports = getModules; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we need this inspiredby as it's self referential?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ha ha oops. That's left over from when it was living in my project. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe this should live in another package. It was developed for Next.js and not everyone is going to use Next.js. I created a new repo for it:
https://github.com/msabramo/get-react-spectrum-modules
though I do wonder if it will have more "gravitas" if the repo lives under some more official scope like
@adobeor@react-spectrum...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, we do have a monorepo, so it doesn't haven't to live in a separate repo, just in its own package here. I'm not sure what scope we'd give it, maybe start with
@adobe, you can find that one inpackages/@adobe