Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { ViteDevServer } from '../server'
import {
combineSourcemaps,
createDebugger,
createFilter,
ensureWatchedFile,
generateCodeFrame,
} from '../utils'
Expand All @@ -31,7 +30,6 @@ const IIFE_BEGIN_RE =
/(?:const|var)\s+\S+\s*=\s*\(?function\([^()]*\)\s*\{\s*"use strict";/

const validExtensionRE = /\.\w+$/
const jsxExtensionsRE = /\.(?:j|t)sx\b/

// the final build should always support dynamic import and import.meta.
// if they need to be polyfilled, plugin-legacy should be used.
Expand Down Expand Up @@ -275,67 +273,6 @@ export async function transformWithEsbuild(
}
}

export function esbuildPlugin(config: ResolvedConfig): Plugin {
const options = config.esbuild as ESBuildOptions
const { jsxInject, include, exclude, ...esbuildTransformOptions } = options

const filter = createFilter(include || /\.(m?ts|[jt]sx)$/, exclude || /\.js$/)

// Remove optimization options for dev as we only need to transpile them,
// and for build as the final optimization is in `buildEsbuildPlugin`
const transformOptions: EsbuildTransformOptions = {
target: 'esnext',
...esbuildTransformOptions,
minify: false,
minifyIdentifiers: false,
minifySyntax: false,
minifyWhitespace: false,
treeShaking: false,
// keepNames is not needed when minify is disabled.
// Also transforming multiple times with keepNames enabled breaks
// tree-shaking. (#9164)
keepNames: false,
supported: {
...defaultEsbuildSupported,
...esbuildTransformOptions.supported,
},
}

let server: ViteDevServer | undefined

return {
name: 'vite:esbuild',
configureServer(_server) {
server = _server
},
async transform(code, id) {
if (filter(id) || filter(cleanUrl(id))) {
const result = await transformWithEsbuild(
code,
id,
transformOptions,
undefined,
config,
server?.watcher,
)
if (result.warnings.length) {
result.warnings.forEach((m) => {
this.warn(prettifyMessage(m, code))
})
}
if (jsxInject && jsxExtensionsRE.test(id)) {
result.code = jsxInject + ';' + result.code
}
return {
code: result.code,
map: result.map,
moduleType: 'js',
}
}
},
}
}

const rollupToEsbuildFormatMap: Record<
string,
EsbuildTransformOptions['format'] | undefined
Expand Down
Loading