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
Implement custom entry #325
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a3ca889 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
lib/makeWebpackConfig.js
Outdated
index: [customEntry, require.resolve('../src/index.js')], | ||
frame: [customEntry, require.resolve('../src/frame.js')], | ||
preview: [customEntry, require.resolve('../src/preview.js')], |
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.
My one concern with this is you may not want your global styles (for example) to end up in the playroom editor and the playroom frame/preview.
We need this for Braid's playroom, but not everyone else necessarily will. IMO it should be opt-in to apply the entry to all entrypoints, and default to just the frame and preview. This feature should actively be discouraged as a way to style the playroom editor IMO.
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.
I've added an escape hatch in 504da1a
It became clear in seek-oss/braid-design-system#1448 that Playroom needed...
After scanning the module graph, here are the relavant code paths:
entry src/index.js
entry src/frame.js
entry src/preview.js
My first idea was to import a module at the top of each of the webpack-defined
__PLAYROOM_ALIAS__*__
aliases. That's because we might not know which one loads first, if we were to convert the code to ESM/TypeScript (which might happen in #313). So I wasn't convinced if it was a good idea.This implementation loads the entry at the top of each webpack entry:
playroom/lib/makeWebpackConfig.js
Lines 42 to 46 in 3aa9edd
This ensures the entry is imported only once per bundle, which is what we want. It also avoids the dual ESM/CJS package hazard, because the entry is loaded by webpack, not by our own code which can be
import
orrequire
calls.