Skip to content

Conversation

@ctrlplusb
Copy link

This PR enables treeshaking of ESBuild whilst also ensuring that the required Remix polyfills do not get removed during the treeshake. Results in smaller bundle sizes that still work when deployed.

Remix by default opts into treeshaking via the "sideEffects": false config in package.json. Users can opt out per their needs still.

Tested and verified against a deployed application.

@ctrlplusb
Copy link
Author

Woops, test broke as was unable to reference the @remix-run/node package. I copy it into the Remix app now so that package resolution works as expected.

Copy link
Contributor

@fwang fwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ctrlplusb! I just had 2 minor things that I wanted to clarify.

// doesn't appear to guarantee this, we therefore leverage ESBUild's
// `inject` option to ensure that the polyfills are injected at the top of
// the bundle.
inject: [polyfillDest],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does passing in polyfillSource not work?

Copy link
Author

@ctrlplusb ctrlplusb Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not. That was my original implementation, but then ESBuild tried to do package resolution to the referenced remix package which failed the unit tests. If we added the remix package as a dependency to the resources package (or root) then it could work. As a dev dependency maybe, but I felt it better to go this route.

@fwang fwang merged commit 94e5e7b into sst:master Oct 13, 2022
@github-actions github-actions bot mentioned this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants