-
Notifications
You must be signed in to change notification settings - Fork 422
feat: improve code splitting by introducing subpackage entry points #836
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
feat: improve code splitting by introducing subpackage entry points #836
Conversation
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. |
Thanks for the pull request, but I'm not sure I understand what you are trying to achieve here and how. You're referencing my own comment... in an already solved issue. I don't quite get it. You seem to claim that it's possible to detect at compile time which strings are used as the |
I apologize for the lack of detail, but I noticed that tree-shaking wasn't functioning as intended, particularly in Vite. I attempted to use The only way I managed to achieve a smaller bundle was by separating Let me know your thoughts and if you have any feedback! |
I've made some changes to the Stackblitz to separate the reproduction into separate pages to visualize the JS size differences better. |
Thanks for clarifying.
I should point out though that the fix you're proposing involves a major
breaking change to the API, which I won't be merging lightly. Before I do
merge it I would really like to find out why the current implementation
isn't working and if there's some way to make it work. If you would give a
hand in investigating that, I would very much appreciate it. If no, that's
fine as well, but then I'll have to do it myself.
PS. Haven't yet tried to reproduce the problem you're reporting or tried
your fix. Just my initial general thoughts about this.
…On Wed, Mar 5, 2025, 18:52 Rui Duarte ***@***.***> wrote:
I've made some changes to the Stackblitz to separate the reproduction into
separate pages to visualize the JS size differences better.
—
Reply to this email directly, view it on GitHub
<#836 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA43OM4ESFVRQ36Q5WRT5D2S4TTRAVCNFSM6AAAAABYMBYU36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBRGUYTQNBZGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
[image: ruijdacd]*ruijdacd* left a comment
(sql-formatter-org/sql-formatter#836)
<#836 (comment)>
I've made some changes to the Stackblitz to separate the reproduction into
separate pages to visualize the JS size differences better.
—
Reply to this email directly, view it on GitHub
<#836 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA43OM4ESFVRQ36Q5WRT5D2S4TTRAVCNFSM6AAAAABYMBYU36VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBRGUYTQNBZGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
[ { ***@***.***": "http://schema.org", ***@***.***": "EmailMessage",
"potentialAction": { ***@***.***": "ViewAction", "target": "
#836 (comment)",
"url": "
#836 (comment)",
"name": "View Pull Request" }, "description": "View this Pull Request on
GitHub", "publisher": { ***@***.***": "Organization", "name": "GitHub", "url": "
https://github.com" } } ]
|
Yeah, totally! I didn't except this to get released quickly. I'd be happy to help out wherever needed |
So, I analyzed this thing and found out that this code splitting did work as expected in the 12.0.0 version where it was first introduced. It was still working in Not sure which of the changes from 14 to 15 might have caused it to break. |
So, the cause seems to be #670. That change alone was released as Strangely there's a comment that says:
However the end result seems to be the opposite. Hmm... |
As reported in #836 (comment), my previous changes from #670 broke the ability for this package to be tree-shaken. This PR takes the other approach I had proposed in #604: it runs `tsc` twice, once to produce a CJS build and once to produce an ESM one. It writes a `package.json` file containing `{"type": "commonjs"}` to `dist/cjs/package.json` so that the files in that directory are treated as CJS. Since #670 introduced an `exports` field, the internal changes to paths shouldn't be visible to consumers, so this should be safe to release as a patch or minor version. That said, I wouldn't blame you if you wanted to release this as a major version to play it safe.
@ruijdacd I've released |
This PR introduces a solution outlined in this comment, which enables more granular control over the bundle output.
Current Problem
When utilizing the
formatDialect
API, the entire package is bundled together instead of just the specificdialect
provided by the user. This results in unnecessary bloat in the bundle size.To illustrate this issue, here is a simple reproduction of a Vite app. In this example, both
format(SQL_QUERY, { language: "postgresql" })
andformatDialect(SQL_QUERY, { dialect: postgresql })
produce the same bundle size, demonstrating the problem clearly.You can view the example here: