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

[Feature Request]: Add an option for setting charset #267

Closed
jw-foss opened this issue Jun 3, 2021 · 2 comments
Closed

[Feature Request]: Add an option for setting charset #267

jw-foss opened this issue Jun 3, 2021 · 2 comments

Comments

@jw-foss
Copy link

jw-foss commented Jun 3, 2021

Background:

I am using this plugin to compile one of my locale file which contains utf-8 charset instead of simple ascii word.

Example

Say we have this file:

locale.zh_CN.ts

export default {
  picker: {
    confirm: "确定",
    clear: "清除",
  },
  // ...
}

If I run the compiler with options:

build.js

const path = require('path')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const rollup = require('rollup')
// const typescript = require('rollup-plugin-typescript2')
const esbuild = require('rollup-plugin-esbuild')

const root = path.resolve(__dirname, '..');
const file = process.argv[2];
const defaultOpts = {
  input: path.resolve(root, file),
  plugins: [
    nodeResolve(),
    esbuild()
  ],
  external() {
    return true
  },
}

const run = async (name) => {
  const esm = {
    format: 'es',
    file: `es/${name}`,
  };
  const cjs = {
    format: 'cjs',
    file: `lib/${name}`,
    exports: 'named',
  }

  const bundle = await rollup.rollup(defaultOpts);
  await Promise.all([bundle.write(esm), bundle.write(cjs)]);
  console.log(name, 'build finished');
}

run(`locale.zh_CN.ts`)

Which produces:

export default {
  colorpicker: {
    confirm: "\u786E\u5B9A",
    clear: "\u6E05\u7A7A"
  }
}

Suggestion

Per Charset for esbuild, esbuild allows user to pass an option called charset.
Should we add an option for users to pass charset to esbuild ?

@leopiccionia
Copy link
Contributor

I've created a PR, because I also need this feature.

My use case is that my code includes a HTML entities parser, and escaping all those Unicode characters adds several KBs to my bundle.

egoist pushed a commit that referenced this issue Apr 6, 2022
@sxzz
Copy link
Collaborator

sxzz commented Sep 20, 2023

Resolved in #330

@sxzz sxzz closed this as completed Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants