Do not escape characters in string literals when they are supported by the specified encoding
See original GitHub issueI was experimenting with babili
and found that the minified code it produces is significantly larger than closure
(100 KiB vs 120 KiB). As it turns out, the problem is caused by the way babili
handles (unicode) string literals.
Suppose that the code contains the string "теѕт"
(all Cyrillic characters). Then babili
converts it to "\u0442\u0435\u0455\u0442"
. OTOH, closure
with the --charset utf8
option leaves the string in the original form. In fact, with that flag, closure
converts "\u0442\u0435\u0455\u0442"
to "теѕт"
.
So I propose to introduce to babili
an option similar to closure
’s --charset
. Of course, this should use a conservative setting by default (eg ascii), because otherwise the minified script would then require to be loaded with charset="..."
in the <script>
tag.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:8 (1 by maintainers)
Top GitHub Comments
Actually minify makes code larger for utf-8 files, for now you can use this:
code = code.replace(/\\u([\d\w]{4})/gi, (m, g) => String.fromCharCode(parseInt(g, 16)))
Your workaround helps, however,
babel-minify
does this also, ifbabel-core
did not. At least, when used as part ofbabel-minify-webpack-plugin
, when minification becomes a separate stage…