@@ -18,7 +18,6 @@ import type { ViteDevServer } from '../server'
1818import {
1919 combineSourcemaps ,
2020 createDebugger ,
21- createFilter ,
2221 ensureWatchedFile ,
2322 generateCodeFrame ,
2423} from '../utils'
@@ -31,7 +30,6 @@ const IIFE_BEGIN_RE =
3130 / (?: c o n s t | v a r ) \s + \S + \s * = \s * \( ? f u n c t i o n \( [ ^ ( ) ] * \) \s * \{ \s * " u s e s t r i c t " ; /
3231
3332const validExtensionRE = / \. \w + $ /
34- const jsxExtensionsRE = / \. (?: j | t ) s x \b /
3533
3634// the final build should always support dynamic import and import.meta.
3735// if they need to be polyfilled, plugin-legacy should be used.
@@ -275,67 +273,6 @@ export async function transformWithEsbuild(
275273 }
276274}
277275
278- export function esbuildPlugin ( config : ResolvedConfig ) : Plugin {
279- const options = config . esbuild as ESBuildOptions
280- const { jsxInject, include, exclude, ...esbuildTransformOptions } = options
281-
282- const filter = createFilter ( include || / \. ( m ? t s | [ j t ] s x ) $ / , exclude || / \. j s $ / )
283-
284- // Remove optimization options for dev as we only need to transpile them,
285- // and for build as the final optimization is in `buildEsbuildPlugin`
286- const transformOptions : EsbuildTransformOptions = {
287- target : 'esnext' ,
288- ...esbuildTransformOptions ,
289- minify : false ,
290- minifyIdentifiers : false ,
291- minifySyntax : false ,
292- minifyWhitespace : false ,
293- treeShaking : false ,
294- // keepNames is not needed when minify is disabled.
295- // Also transforming multiple times with keepNames enabled breaks
296- // tree-shaking. (#9164)
297- keepNames : false ,
298- supported : {
299- ...defaultEsbuildSupported ,
300- ...esbuildTransformOptions . supported ,
301- } ,
302- }
303-
304- let server : ViteDevServer | undefined
305-
306- return {
307- name : 'vite:esbuild' ,
308- configureServer ( _server ) {
309- server = _server
310- } ,
311- async transform ( code , id ) {
312- if ( filter ( id ) || filter ( cleanUrl ( id ) ) ) {
313- const result = await transformWithEsbuild (
314- code ,
315- id ,
316- transformOptions ,
317- undefined ,
318- config ,
319- server ?. watcher ,
320- )
321- if ( result . warnings . length ) {
322- result . warnings . forEach ( ( m ) => {
323- this . warn ( prettifyMessage ( m , code ) )
324- } )
325- }
326- if ( jsxInject && jsxExtensionsRE . test ( id ) ) {
327- result . code = jsxInject + ';' + result . code
328- }
329- return {
330- code : result . code ,
331- map : result . map ,
332- moduleType : 'js' ,
333- }
334- }
335- } ,
336- }
337- }
338-
339276const rollupToEsbuildFormatMap : Record <
340277 string ,
341278 EsbuildTransformOptions [ 'format' ] | undefined
0 commit comments