fix(css): remove ?used hack (fixes #6421, #8245)#8278
Merged
patak-dev merged 2 commits intovitejs:mainfrom May 22, 2022
Merged
Conversation
Member
Author
|
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. |
7 tasks
7 tasks
sapphi-red
added a commit
to sapphi-red/vite
that referenced
this pull request
Jun 5, 2022
9 tasks
This was referenced Jun 30, 2022
sapphi-red
added a commit
to sapphi-red/vite
that referenced
this pull request
Jul 3, 2022
This reverts commit 0b25cc1.
patak-dev
pushed a commit
that referenced
this pull request
Jul 3, 2022
This reverts commit 0b25cc1.
This was referenced Jul 3, 2022
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This
?usedhack 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
linkedvariable andimportedvariable 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
linkedis removed from output.importedis 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
?usedhack and changes the css default export toexport default /* #__PURE__ */ (() => ${JSON.stringify(content)})()which I showed above.I also tested with this project (stackblitz).
?usedhackfixes #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).