@@ -17,8 +17,12 @@ import {
1717 createDebugger ,
1818 dataUrlRE ,
1919 externalRE ,
20+ isAstroExt ,
21+ isHtmlExt ,
2022 isObject ,
2123 isOptimizable ,
24+ isSvelteExt ,
25+ isVueExt ,
2226 moduleListContains ,
2327 multilineCommentsRE ,
2428 normalizePath ,
@@ -366,7 +370,7 @@ function esbuildScanPlugin(
366370 let raw = fs . readFileSync ( path , 'utf-8' )
367371 // Avoid matching the content of the comment
368372 raw = raw . replace ( commentRE , '<!---->' )
369- const isHtml = path . endsWith ( '.html' )
373+ const isHtml = isHtmlExt ( path )
370374 const regex = isHtml ? scriptModuleRE : scriptRE
371375 regex . lastIndex = 0
372376 let js = ''
@@ -394,7 +398,7 @@ function esbuildScanPlugin(
394398 let loader : Loader = 'js'
395399 if ( lang === 'ts' || lang === 'tsx' || lang === 'jsx' ) {
396400 loader = lang
397- } else if ( path . endsWith ( '.astro' ) ) {
401+ } else if ( isAstroExt ( path ) ) {
398402 loader = 'ts'
399403 }
400404 const srcMatch = openTag . match ( srcRE )
@@ -445,7 +449,7 @@ function esbuildScanPlugin(
445449 // Especially for Svelte files, exports in <script context="module"> means module exports,
446450 // exports in <script> means component props. To avoid having two same export name from the
447451 // star exports, we need to ignore exports in <script>
448- if ( path . endsWith ( '.svelte' ) && context !== 'module' ) {
452+ if ( isSvelteExt ( path ) && context !== 'module' ) {
449453 js += `import ${ virtualModulePath } \n`
450454 } else {
451455 js += `export * from ${ virtualModulePath } \n`
@@ -457,7 +461,7 @@ function esbuildScanPlugin(
457461 // anywhere in a string. Svelte and Astro files can't have
458462 // `export default` as code so we know if it's encountered it's a
459463 // false positive (e.g. contained in a string)
460- if ( ! path . endsWith ( '.vue' ) || ! js . includes ( 'export default' ) ) {
464+ if ( ! isVueExt ( path ) || ! js . includes ( 'export default' ) ) {
461465 js += '\nexport default {}'
462466 }
463467
0 commit comments