Skip to content

feat!: set esbuild default charset to utf8#10753

Merged
patak-cat merged 4 commits intovitejs:mainfrom
azat-io:fix/charset
Nov 9, 2022
Merged

feat!: set esbuild default charset to utf8#10753
patak-cat merged 4 commits intovitejs:mainfrom
azat-io:fix/charset

Conversation

@azat-io
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

azat-io commented Nov 2, 2022

An example of a real bundle:

image

@patak-cat patak-cat added the p3-significant High priority enhancement (priority) label Nov 3, 2022
@patak-cat patak-cat added this to the 4.0 milestone Nov 3, 2022
return {
...options,
minify: true,
charset: 'utf8',
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@patak-cat patak-cat 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-cat
patak-cat previously approved these changes Nov 9, 2022
@patak-cat patak-cat requested a review from bluwy November 9, 2022 13:59
@patak-cat patak-cat 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
Copy Markdown

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-cat
Copy link
Copy Markdown
Member

Yes, this is only for v4.

@samyarkd
Copy link
Copy Markdown

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-cat
Copy link
Copy Markdown
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.

4 participants