-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
De-duplicate Webpack build, especially components/
#929
Conversation
`component` depends on `element`. :(
Looks good to me. Will we also need to go through the files and change where modules are being imported from? Or is webpack smart enough to not duplicate once a build is created for that directory? Here is the current list to illustrate what I mean.
|
This is the part that's not working yet - I would expect to see the 118kb file for I suspect something is still missing in the webpack config. |
4d4416b
to
9b29ebc
Compare
Before this PR there's actually a lot of duplication in the built files. Multiple copies of
However, there is still a lot of duplication - - import IconButton from 'components/icon-button';
+ import { IconButton } from 'components'; |
9b29ebc
to
63b2db4
Compare
- Fix entry point order to match actual dependencies - Fix externals (`wp.*` externals not needed)
components/
directory separatelycomponents/
and other parts of Webpack build
components/
and other parts of Webpack buildcomponents/
This PR should be ready for review now. It shaves 200 KB off of the production build size by adding a new It works by registering each of our top-level entry points like I saw #901 (comment) after I already started restructuring imports in this way. The one difference is that everything should be imported from Current sizes:
Final statistics:
|
export { default as Spinner } from './spinner'; | ||
export { default as Toolbar } from './toolbar'; | ||
|
||
export { default as withFocusReturn } from './higher-order/with-focus-return'; |
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 don't think we should export this in the root module. I'm thinking we should create a index.js
in the ./higher-order/
folder to be able to import those as import { withFocusReturn } from 'components/higher-order'
;
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 I just saw your comment #929 (comment)
I still think we should make a distinction between importing components and HoC.
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.
How do we make this work like wp.components.something
behind the scenes?
I think this could be solved separately, in any case.
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.
Nice Work! Verified that the build size is significantly smaller. LGTM, any issues can be cycled back to in another PR I think as this resolves things for the current structure.
I've created #941 to discuss next steps. |
I think this broke master. There's an error if you open the inspector. |
Confirmed this broke a lot of components. I fixed this in a branch 17741f4 but we should probably fix this separately |
While looking at #926 I noticed that we are probably duplicating some code in the
components/
directory across built files. For example, we importIconButton
in botheditor/header/tools/preview-button.js
andblocks/editable/format-toolbar.js
.If we split
components/
out into a separate build + entry point, we should be able to resolve this issue, and also make our common components available viawp.components
, which seems good for reusability.This PR is an attempt at doing this, but it's not working for some reason. Here are the build sizes before this PR:
and after: