Skip to content

Commit

Permalink
fix: set default esbuild charset
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Nov 8, 2022
1 parent 87aad09 commit b6878cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: 'es2020',
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -59,6 +60,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -88,6 +90,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: 'es2020',
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -119,6 +122,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -150,6 +154,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'cjs'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'cjs',
keepNames: true,
Expand Down Expand Up @@ -180,6 +185,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'es'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'esm',
keepNames: true,
Expand Down Expand Up @@ -214,6 +220,7 @@ describe('resolveEsbuildTranspileOptions', () => {
'cjs'
)
expect(options).toEqual({
charset: 'utf8',
target: undefined,
format: 'cjs',
keepNames: true,
Expand Down
8 changes: 0 additions & 8 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ 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 @@ -154,11 +152,6 @@ 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 @@ -637,7 +630,6 @@ export async function resolveConfig(
resolve: resolveOptions,
publicDir: resolvedPublicDir,
cacheDir,
charset: config.charset ?? 'utf8',
command,
mode,
ssr,
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ export function resolveEsbuildTranspileOptions(
// https://github.com/vuejs/core/issues/2860#issuecomment-926882793
const isEsLibBuild = config.build.lib && format === 'es'
const esbuildOptions = config.esbuild || {}

const options: TransformOptions = {
charset: 'utf8',
...esbuildOptions,
charset: config.charset,
target: target || undefined,
format: rollupToEsbuildFormatMap[format],
// the final build should always support dynamic import and import.meta.
Expand Down

0 comments on commit b6878cf

Please sign in to comment.