-
Notifications
You must be signed in to change notification settings - Fork 179
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
Build packages using Rollup #10386
Build packages using Rollup #10386
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
dedupe: [], | ||
}), | ||
babel({ | ||
babelHelpers: 'inline', |
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.
Trying to learn why inline
is used as an option for babelHelpers here
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 used runtime
initially as it was the recommendation, but I got some warnings when building.
(!) Circular dependencies
packages/story-editor/src/masks/index.js -> packages/story-editor/src/elements/index.js -> packages/story-editor/src/elements/elementTypes.js -> packages/story-editor/src/elements/text/index.js -> packages/story-editor/src/elements/text/display.js -> packages/story-editor/src/elements/shared/index.js -> packages/story-editor/src/utils/elementBorder.js -> packages/story-editor/src/masks/index.js
packages/story-editor/src/app/story/index.js -> packages/story-editor/src/app/story/useStoryReducer/reducers/index.js -> packages/story-editor/src/app/story/useStoryReducer/reducers/combineElements.js -> packages/story-editor/src/masks/index.js -> packages/story-editor/src/elements/index.js -> packages/story-editor/src/elements/elementTypes.js -> packages/story-editor/src/elements/text/index.js -> packages/story-editor/src/elements/text/edit.js -> packages/story-editor/src/app/story/index.js
packages/story-editor/src/app/story/index.js -> packages/story-editor/src/app/story/useStoryReducer/reducers/index.js -> packages/story-editor/src/app/story/useStoryReducer/reducers/combineElements.js -> packages/story-editor/src/masks/index.js -> packages/story-editor/src/elements/index.js -> packages/story-editor/src/elements/elementTypes.js -> packages/story-editor/src/elements/text/index.js -> packages/story-editor/src/elements/text/frame.js -> packages/story-editor/src/app/story/index.js
...and 48 more 51 indirect circular dependencies are a lot to resolve. 😵💫 |
I think we may ignore these circular dependency warning for now by using onwarn(warning, warn) {
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
warn(warning);
}
} |
They don't cause the build to error though, so not a big deal to keep them visible and remind os of this technical debt :) |
Yes, maybe a lot of them will be resolved automatically when we break down the |
This comment was marked as resolved.
This comment was marked as resolved.
@swissspidy Can you explain this one a bit from the to-do list?
|
I'm inclined to just ditch our current web worker logic completely. Not a huge fan of the webpack We could take a very simple approach by manually turning it into an inline/embedded web worker (see examples at https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#embedded_workers) using a blob — which is basically what So something like this: function generateBlurHash() {
// ...
}
const blob = new Blob(['('+generateBlurHash.toString()+')()'], {type: 'text/javascript'})
const workerUrl = URL.createObjectURL(blob);
new Worker(workerUrl) At least for the short term this should do the trick. Suggestions welcome!
Sure. Basically right now we have tons of ESLint warnings here on this PR. They are caused by all the changes I did to the They come from eslint-plugin-import, specifically the no-unresolved rule It uses Node-style module resolution by default, which has some open issues about this import-js/eslint-plugin-import#1868 Perhaps using eslint-import-resolver-webpack fixes this? Otherwise I suppose we can just disable this rule until the above issues get fixed. |
Great idea of turning into an inline/embedded web worker using blob 👍 For Eslint warnings, I tried eslint-import-resolver-webpack, but that didn't work for me. Gutenberg also had a similar issue here WordPress/gutenberg#31792 for which they used eslint-import-resolver-node, see /.eslintrc.js#L53 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Tested it after manually merging #10297 and In
I think all import issues were resolved but now we have some node errors. ERROR in ./node_modules/@googleforcreators/story-editor/dist-module/index-276f5876.js
Module not found: Error: Can't resolve './raw' in '/Users/sayedtaqui/playground/react-app/node_modules/@googleforcreators/story-editor/dist-module'
@ ./node_modules/@googleforcreators/story-editor/dist-module/index-276f5876.js 404:624305-624330
@ ./node_modules/@googleforcreators/story-editor/dist-module/index.js
@ ./src/index.js
ERROR in ./node_modules/@googleforcreators/story-editor/dist-module/index-276f5876.js
Module not found: Error: Can't resolve './raw' in '/Users/sayedtaqui/playground/react-app/node_modules/@googleforcreators/story-editor/dist-module'
@ ./node_modules/@googleforcreators/story-editor/dist-module/index-276f5876.js 136:46199-46219
@ ./node_modules/@googleforcreators/story-editor/dist-module/index.js
@ ./src/index.js
ERROR in ./node_modules/@googleforcreators/story-editor/dist-module/index-c3e659ac.js
Module not found: Error: Can't resolve 'fs' in '/Users/sayedtaqui/playground/react-app/node_modules/@googleforcreators/story-editor/dist-module'
@ ./node_modules/@googleforcreators/story-editor/dist-module/index-c3e659ac.js 17:99-117 17:24780-24781
@ ./node_modules/@googleforcreators/story-editor/dist-module/index-276f5876.js
@ ./node_modules/@googleforcreators/story-editor/dist-module/index.js
@ ./src/index.js |
Context
Before we can publish our packages on npm we need a build step for them, ideally to produce both CommonJS and ESM versions.
Summary
This is an attempt at this by leveraging Rollup and several Rollup plugins that fit our needs.
Building packages creates
dist
anddist-module
folders that are then used for distribution.The
src
folder is entirely ignored for publishing on npm.Basic usage:
Relevant Technical Choices
Decided to try Rollup because we're already using it in the project and it was relatively easy to get off the ground.
Changed some imports to avoid circular dependencies, though this still needs more work.
Changed some imports to avoid mixing default imports and named exports. Quote:
Used custom resolvers for webpack and Jest so they continue to look for packages in the
src
folders instead ofdist
.To-do
story-editor
import/no-unresolved
false positivesreact-photo-gallery
User-facing changes
None
Testing Instructions
This PR can be tested by following these steps:
npm run bundle
to build the packages yourselfReviews
Does this PR have a security-related impact?
Not that I could think of
Does this PR change what data or activity we track or use?
No
Does this PR have a legal-related impact?
No
Checklist
Type: XYZ
label to the PRSee #10251