-
-
Notifications
You must be signed in to change notification settings - Fork 39
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: reduce MUI size by using @swc/plugin-transform-imports
#169
Conversation
✅ Deploy Preview for any-viewer ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov ReportBase: 87.40% // Head: 87.39% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #169 +/- ##
==========================================
- Coverage 87.40% 87.39% -0.02%
==========================================
Files 18 18
Lines 1969 1967 -2
Branches 349 349
==========================================
- Hits 1721 1719 -2
Misses 248 248
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@pionxzh does it work in the case of When I attempted the manual solution, I found that it wasn't default exported: Here's the reference on github: |
Lol. I manually copied and modified the import as an example. You are right. |
@anthonyalayo do you mind doing testing on this version? That would be helpful 🙏 |
@pionxzh tested -- unfortunately due to the lack of consistency within
It was the same issue I hit when I did it manually here. I found an open PR on I'm searching for some tweaks that could make this work. |
@anthonyalayo Thanks. Wow I didn't expect that 😢 |
@pionxzh , I think I understand the entire picture now. First of all, here's the fix to make your PR build:
With that being said, it still ends up pulling other @mui dependencies in during development. I updated my original PR, #168, with more details about exactly why this is happening and why that fix is working. Let me know what you think @pionxzh @rtritto. |
070fe67
to
37f26d6
Compare
closed as in favor of #168 |
@pionxzh @anthonyalayo Remove use of Example:
|
Good point. It shouldn't bring any difference. And the |
Should this PR be reopened in draft for the future? |
I will reopen when things get right 😄 |
37f26d6
to
a85a021
Compare
TODO: rewrite the |
@pionxzh ideally we have something like:
but because your |
Yes, so the format array should be refactored to be accpet only one format |
@pionxzh , nice fix! |
I have finished the necessary changes. |
@pionxzh that's right, the size of the bundle should remain the same during builds, it's the webpack import bloat that occurs during builds/runs. Let me check the module count |
Unfortunately I'm having a bunch of errors and I'm not sure where they are coming from yet @pionxzh. It's some sort of...mix and match with cjs and esm?
|
Directory import... Let me rewrite it to index.js 👀 |
@pionxzh build is working now! But the module count is still high. I re-visited the PR I made for doing the imports manually, check this out: Left: Manual Paths (my PR) Notice how the manual paths version barely makes any imports to @mui? I believe there is some optimization step during the build process in rollup that is doing this. The inlining of trivial code is what makes json-viewer much faster. My first thought - is it possible to do the swc transform imports earlier on in the build process? |
What is the boilerplate you use? I want to test this locally. But none of them shows the count of modules 😞 |
@pionxzh i'm presently using https://github.com/mantinedev/mantine-next-template but either |
@anthonyalayo This is the result I get with CRA(followed your instruction in the RFC) + latest package
main (local build)
PR 169 (swc transform)
PR 168 (inline path import)
And, this is the bundled result |
@pionxzh here's the step by step for CRA:
There's one stats object from the return value of webpack's I just followed the steps above with the following CRA app:
Then I ran
You can see 750+ modules were loaded, but only 17 were actually needed. That's from the latest release of |
Actually since you mention that, that was something odd. On the branch right now, it isn't inlining the functions / cleaning up the imports. I think one of the other changes broke that desired behavior somehow? https://github.com/TexteaInc/json-viewer/pull/168/commits I just re-did the changes locally (manually did the path imports), hit build, and saw that output I pasted above. |
I think you might need this line.
|
@pionxzh I agree, you're right. The remaining bloat is coming from One thing that would be a nice improvement afterwards, is to un-bundle the builds that aren't meant for the browser. Non-browser builds will most likely be pulling this library into their own build process, so bundling ahead of time makes it harder on the user's bundler to tree shake code. For example, if the copy to clipboard feature isn't used, then it may not get imported. I was following tickets on For reference, here's a rendering of a nextjs trace I did with a blank project that just uses
|
Nice. The trace in Next.js looks quite clean. For the un-bundle, it's a good suggestion. Thank. |
…TexteaInc#169)" This reverts commit f5739d6.
* fix: reduce MUI size by using `@swc/plugin-transform-imports` * style: apply ESLint rules to enforce correct import path * fix: fix eslint error message * fix: add rule for `@mui/material/styles` * ci: rewrite MUI import differently for esm and cjs * fix: prevent directory import in ESM build
related: #140 #168
This PR introduced @swc/plugin-transform-imports to minimize the bundle size of MUI.
It will transform the import statement into path import to reduce the amount of modules being pulled in.