Skip to content
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!: set esbuild default charset to utf8 #10753

Merged
merged 4 commits into from Nov 9, 2022
Merged

Conversation

azat-io
Copy link
Contributor

@azat-io azat-io commented Nov 2, 2022

image

Currently, if I use a language other than English in my javascript code, my bundle gets very large. To avoid this, I have to use a Terser. For example, Terser preserves "丂", but esbuild seems to convert it to "\u4E02".

In order to solve the problem and start using esbuild without fear, we need to add charset.

@azat-io
Copy link
Contributor Author

azat-io commented Nov 2, 2022

An example of a real bundle:

image

@patak-dev patak-dev added the p3-significant High priority enhancement (priority) label Nov 3, 2022
@patak-dev patak-dev added this to the 4.0 milestone Nov 3, 2022
@@ -375,6 +375,7 @@ export function resolveEsbuildTranspileOptions(
return {
...options,
minify: true,
charset: 'utf8',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think charset should be moved up to the definition of options so we have consistent usage of utf8 by default. We also need to define it before the esbuildOptions spread so the user can overwrite it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@patak-dev patak-dev changed the title fix: add charset to esbuild build options feat!: switch esbuild to charset utf8 by default Nov 7, 2022
@azat-io azat-io force-pushed the fix/charset branch 2 times, most recently from 9e67fe5 to b6878cf Compare November 8, 2022 23:05
@azat-io azat-io changed the title feat!: switch esbuild to charset utf8 by default feat!: set esbuild default charset to utf8 Nov 8, 2022
patak-dev
patak-dev previously approved these changes Nov 9, 2022
@patak-dev patak-dev requested a review from bluwy November 9, 2022 13:59
@patak-dev patak-dev merged commit 4caf4b6 into vitejs:main Nov 9, 2022
@azat-io azat-io deleted the fix/charset branch November 9, 2022 16:36
@samyarkd
Copy link

Is this only for v4 ? Because I get the exact same error in version ^3.2.2. I will upgrade to v4 this should be fixed right ?

@patak-dev
Copy link
Member

Yes, this is only for v4.

@samyarkd
Copy link

Yes, this is only for v4.

I tried to upgrade to v4 but i encountered many other problems because of other packages that do not support v4. Are you planing on fixing this for v3 too? This problem happened to me today suddenly.

@patak-dev
Copy link
Member

@samyarkd I suggest you still try to upgrade to v4, but if you need to stay in v3, you should be able to set charset: 'utf8' using https://vitejs.dev/config/shared-options.html#esbuild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants