Skip to content

Commit

Permalink
feat: add charset config option
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 8, 2022
1 parent a4d2e26 commit 87aad09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 0 additions & 2 deletions packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: 'es2020',
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -151,7 +150,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'cjs'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'cjs',
keepNames: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export type PluginOption =
| PluginOption[]
| Promise<Plugin | false | null | undefined | PluginOption[]>

type Charset = 'ascii' | 'utf8'

export interface UserConfig {
/**
* Project root directory. Can be an absolute path, or a path relative from
Expand Down Expand Up @@ -152,6 +154,11 @@ export interface UserConfig {
* each command, and can be overridden by the command line --mode option.
*/
mode?: string
/**
* Charset
* @default 'utf8'
*/
charset?: Charset
/**
* Define global variable replacements.
* Entries will be defined on `window` during dev and replaced during build.
Expand Down Expand Up @@ -630,6 +637,7 @@ export async function resolveConfig(
resolve: resolveOptions,
publicDir: resolvedPublicDir,
cacheDir,
charset: config.charset ?? 'utf8',
command,
mode,
ssr,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export function resolveEsbuildTranspileOptions(
const esbuildOptions = config.esbuild || {}
const options: TransformOptions = {
...esbuildOptions,
charset: config.charset,
target: target || undefined,
format: rollupToEsbuildFormatMap[format],
// the final build should always support dynamic import and import.meta.
Expand Down Expand Up @@ -375,7 +376,6 @@ export function resolveEsbuildTranspileOptions(
return {
...options,
minify: true,
charset: 'utf8',
treeShaking: true
}
}
Expand Down

0 comments on commit 87aad09

Please sign in to comment.