Skip to content

Commit

Permalink
refactor: set defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 1, 2024
1 parent eefe895 commit 51e3d13
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 11 deletions.
7 changes: 0 additions & 7 deletions packages/vite/src/node/__tests__/plugins/esbuild.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: 'es2020',
format: 'esm',
Expand Down Expand Up @@ -64,7 +63,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: undefined,
format: 'esm',
Expand Down Expand Up @@ -95,7 +93,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: 'es2020',
format: 'esm',
Expand Down Expand Up @@ -128,7 +125,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: undefined,
format: 'esm',
Expand Down Expand Up @@ -161,7 +157,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'cjs',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: undefined,
format: 'cjs',
Expand Down Expand Up @@ -193,7 +188,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'es',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: undefined,
format: 'esm',
Expand Down Expand Up @@ -229,7 +223,6 @@ describe('resolveEsbuildTranspileOptions', () => {
'cjs',
)
expect(options).toEqual({
charset: 'utf8',
loader: 'js',
target: undefined,
format: 'cjs',
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,9 @@ export async function resolveConfig(
? false
: {
jsxDev: !isProduction,
// change defaults that fit better for vite
charset: 'utf8',
legalComments: 'none',
...config.esbuild,
},
server,
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ async function prepareEsbuildOptimizerRun(
metafile: true,
plugins,
charset: 'utf8',
legalComments: 'none',
...esbuildOptions,
supported: {
...defaultEsbuildSupported,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ function resolveMinifyCssEsbuildOptions(
options: ESBuildOptions,
): TransformOptions {
const base: TransformOptions = {
charset: options.charset ?? 'utf8',
charset: options.charset,
logLevel: options.logLevel,
logLimit: options.logLimit,
logOverride: options.logOverride,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export async function replaceDefine(

const result = await transform(code, {
loader: 'js',
charset: esbuildOptions.charset ?? 'utf8',
charset: esbuildOptions.charset,
platform: 'neutral',
define,
sourcefile: id,
Expand Down
2 changes: 0 additions & 2 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ export function esbuildPlugin(config: ResolvedConfig): Plugin {
// and for build as the final optimization is in `buildEsbuildPlugin`
const transformOptions: TransformOptions = {
target: 'esnext',
charset: 'utf8',
...esbuildTransformOptions,
minify: false,
minifyIdentifiers: false,
Expand Down Expand Up @@ -390,7 +389,6 @@ export function resolveEsbuildTranspileOptions(
const esbuildOptions = config.esbuild || {}

const options: TransformOptions = {
charset: 'utf8',
...esbuildOptions,
loader: 'js',
target: target || undefined,
Expand Down

0 comments on commit 51e3d13

Please sign in to comment.