-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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(css): remove ?used
hack (fixes #6421, #8245)
#8278
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too awesome 🔥
This PR makes the output of const content = (() => "body{color:red}")()
console.log(content) . But this might hurt runtime perf if const content = (function () { return "body{color:red}"})()
console.log(content) This might be better for perf though the code is longer. I'm not making a PR for this as I didn't measure the perf and it is an edge case but still leaving a note here. |
This reverts commit 0b25cc1.
This reverts commit 0b25cc1.
Description
This
?used
hack was introduced by 3e3c203.At that time, esbuild v0.12.25 was used. This version of esbuild had trouble with tree-shaking.
This is the reproduction with esbuild repl. You can see
linked
variable andimported
variable exists in the output.But now Vite uses esbuild v0.14.38 and tree-shake works. This is the reproduction with esbuild repl. You can see
linked
is removed from output.imported
is still included because ofnew URL('---', import.meta.url).href
.So here it needs to be marked as pure.
esbuild 0.13.0+ supports
/* #__PURE__ */
and it worked if I marked by using it (esbuild repl).The same code worked successfully with terser too.
This PR removes the
?used
hack and changes the css default export toexport default /* #__PURE__ */ (() => ${JSON.stringify(content)})()
which I showed above.I also tested with this project (stackblitz).
?used
hackfixes #6421
fixes #8245
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).