-
Notifications
You must be signed in to change notification settings - Fork 78
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
fix(treeshaking): fix treeshaking and add esm and umd versions #1036
Conversation
Deploy preview for carbon-addons-iot-react ready! Built with commit 26ff0ca https://deploy-preview-1036--carbon-addons-iot-react.netlify.com |
@davidicus so the sideEffects false really was required for treeshaking to work? Sorry for the bad info about that? |
@scottdickerson Yep, here's an example from webpack From the link: (I replaced the example package name with ours)
|
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.
Outputs all 4 directories as intended on yarn build
@@ -61,36 +23,6 @@ Map { | |||
"kind": "primary", | |||
"loading": false, | |||
}, | |||
"propTypes": Object { |
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'm seeing most (if not all) propTypes removed from the api snapshot. Is this intentional? I thought the purpose of this file was to compare the APIs from build to build, release to release, etc.
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.
Yes part of this is intended, but we shouldn't be stripping them completely. They should be wrapped in a conditional (see my review), so consuming applications still get proptype warnings.
The broader scope here is that there is a bug with Terser, with a decent workaround synopsis here, where tree shaking breaks when 2 or more static properties are assigned to a function. Our components typically have defaultProps
and propTypes
. Carbon ran into the same issue recently causing them to revert an update to their build.
We can avoid this by wrapping prop types in a conditional so production builds have only one static property on the component, which allows tree shaking to not break.
I have a couple questions regarding this, but these questions should not impact the approval of the PR.
|
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.
In addition to these changes, could the documentation in the root README.MD
be modified to specify the new scss/styles.scss
entrypoint vs the one in lib/scss/styles.scss
?
@stuckless I'll step in and answer as I've occasionally been pairing with @davidicus on this for the past week or so.
Yes, originally the entire library was included no matter which components were imported. About ~2.5mb as I recall. After testing in a
To enable with Webpack as your module bundler: (below from the link)
Yep, shouldn't be any change. Do note that webpack will likely automatically begin importing the esm version by default instead of the lib version because of the addition of
Yes. It relies on the static structure of ES2015 module syntax resolving relative and named imports
Likely no difference to your app's build times, but If your app only uses a small subset of components, tree shaking will provide smaller bundle(s) delivered in production environments. |
@tay1orjones thx... that great info. btw, is Carbon doing this as well? |
@stuckless Yes, Carbon provides an esm build that supports tree shaking. The bug referenced in my comment above was when they tried to ship a single entrypoint generated by Rollup for their ESM and CJS bundles. |
closing in favor of #1045. Will address all comments in other PR. |
Closes #993 closes #1011
Summary
Changes to our build to allow for es and umd versions and to allow for treeshaking in consuming applications.
Change List (commits, features, bugs, etc)
Acceptance Test (how to verify the PR)
yarn build should output a lib, es, umd, and scss folder.