Search code examples
javascripthtmlbundleparceljs

Parcel character encoding


In Parcel 2 RC we use ES modules, so we need to add the type="module" attribute to the script tags (Otherwise, we get an error message). When we chose a script tag to be a module the code is treated as a JavaScript module, and the processing of the script content is not affected by the charset. My question is: How to specify, to the module, the encoding ("utf-8") so that we can use special characters?

 <script type="module" src="app.js"></script>

Solution

  • According to the mozilla docs, the charset field of the <script> tag is deprecated:

    If present, its value must be an ASCII case-insensitive match for "utf-8". It’s unnecessary to specify the charset attribute, because documents must use UTF-8, and the script element inherits its character encoding from the document.

    So I think you can just use special characters in your .js files by default, and parcel will respect them.

    See this example in the parcel repl