Skip to content
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: Mangle internal export names #1963

Closed
wants to merge 3 commits into from
Closed

build: Mangle internal export names #1963

wants to merge 3 commits into from

Conversation

shuding
Copy link
Member

@shuding shuding commented May 13, 2022

In #1962 we added a shared internal module for all subpath imports to use. However the named exports can't be minified (by many bundlers) because they're across modules. Here we are using TypeScript enums to ensure that 1) these names can be minified, and 2) we can still import the correct utils with typings easily.

This decreases the bundle size by 800+ bytes (minified) for just 'swr', and will probably save more if other subpaths are used such as 'swr/infinite'.

@shuding shuding requested a review from huozhi as a code owner May 13, 2022 19:34
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 13, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6b5cc06:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

core/index.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,31 @@
export const enum InternalUtils {
Copy link
Member

Choose a reason for hiding this comment

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

maybe explain why we need to have this as comment here, to help contributors understand better this is for size compression purpose

@huozhi huozhi changed the title chore: Mangle internal export names build: Mangle internal export names May 13, 2022
@shuding
Copy link
Member Author

shuding commented May 14, 2022

Closing for now as most of bundlers are already handling this today. For the other cases that modules can’t be bundled together (bundleless solutions, or ending up in different chunks somehow), we will wait and see if it has an impact or not.

@shuding shuding closed this May 14, 2022
@huozhi huozhi deleted the shu/a825 branch January 23, 2023 14:45
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.

None yet

2 participants