Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(build): integrate tree-shaker for improved bundle optimization #4994

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

johnsoncodehk
Copy link
Member

Copy link

pkg-pr-new bot commented Nov 7, 2024

Open in Stackblitz

vue-component-meta

npm i https://pkg.pr.new/vuejs/language-tools/vue-component-meta@4994

vue-component-type-helpers

npm i https://pkg.pr.new/vuejs/language-tools/vue-component-type-helpers@4994

@vue/language-plugin-pug

npm i https://pkg.pr.new/vuejs/language-tools/@vue/language-plugin-pug@4994

@vue/language-core

npm i https://pkg.pr.new/vuejs/language-tools/@vue/language-core@4994

@vue/language-server

npm i https://pkg.pr.new/vuejs/language-tools/@vue/language-server@4994

@vue/language-service

npm i https://pkg.pr.new/vuejs/language-tools/@vue/language-service@4994

vue-tsc

npm i https://pkg.pr.new/vuejs/language-tools/vue-tsc@4994

@vue/typescript-plugin

npm i https://pkg.pr.new/vuejs/language-tools/@vue/typescript-plugin@4994

commit: 2e4324c

@johnsoncodehk
Copy link
Member Author

@kermanx I think this PR is almost successful, but tree-shaker seems to have some template string/regex conversion problems, can you take a look?

@kermanx
Copy link
Collaborator

kermanx commented Dec 18, 2024

@kermanx I think this PR is almost successful, but tree-shaker seems to have some template string/regex conversion problems, can you take a look?

Yes, I've noticed that bug, but I can't immediately solve it because I need to investigate how to escape the template literal in oxc 🥲.

@kermanx
Copy link
Collaborator

kermanx commented Dec 19, 2024

I've used a workaround to solve the template literal escaping issue.

Currently, this PR is tree-shaking thousands of input files, which may lose many import chances compared to tree-shaking the bundled js.

I found that the server.cjs produced by esbuild will make the tree shaker stuck for a long time. However, tree-shaking works well on the Rollup output in #4998. As a rough estimation, Tree-shaking can finish in about 30s on the Rollup output in #4998, and make the js size about 5% smaller.

@johnsoncodehk
Copy link
Member Author

Unfortunately the output file is currently corrupt and still needs to be investigated.

#4998 changes the project dependencies too much, so it's relatively difficult to merge (and I haven't finished reviewing all the changes yet), and if we can successfully merge this PR first, and move on to #4998 in the future, I think there is no harm.

@kermanx
Copy link
Collaborator

kermanx commented Dec 20, 2024

Unfortunately the output file is currently corrupt and still needs to be investigated.

I've fixed another bug. And I can't find more problems myself now.

@johnsoncodehk johnsoncodehk marked this pull request as ready for review December 20, 2024 10:34
@johnsoncodehk johnsoncodehk force-pushed the master branch 2 times, most recently from c3e80dc to 209717c Compare December 20, 2024 21:05
@kermanx
Copy link
Collaborator

kermanx commented Dec 26, 2024

I just found that the filter used to be /\.js/, which accepts *.json. And tree-shaker can't parse JSON, which results in an empty output 🥲

Sadly, after this fix, tree-shaker can only make the bundle size less than 0.01 MB smaller. This is quite expected because tree-shaker aims to remove unused code, but individual source modules always don't have useless code themselves. I will work on making tree-shaking the bundled code work.

@kermanx kermanx marked this pull request as draft December 26, 2024 13:36
@KazariEX KazariEX force-pushed the master branch 2 times, most recently from 5ae4b38 to d782f70 Compare March 2, 2025 10:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants