@@ -6,18 +6,14 @@ import type { Loader, OnLoadResult, Plugin } from 'esbuild'
6
6
import { build , transform } from 'esbuild'
7
7
import colors from 'picocolors'
8
8
import type { ResolvedConfig } from '..'
9
- import {
10
- JS_TYPES_RE ,
11
- KNOWN_ASSET_TYPES ,
12
- OPTIMIZABLE_ENTRY_RE ,
13
- SPECIAL_QUERY_RE
14
- } from '../constants'
9
+ import { JS_TYPES_RE , KNOWN_ASSET_TYPES , SPECIAL_QUERY_RE } from '../constants'
15
10
import {
16
11
cleanUrl ,
17
12
createDebugger ,
18
13
dataUrlRE ,
19
14
externalRE ,
20
15
isObject ,
16
+ isOptimizable ,
21
17
moduleListContains ,
22
18
multilineCommentsRE ,
23
19
normalizePath ,
@@ -189,10 +185,6 @@ function esbuildScanPlugin(
189
185
'@vite/env'
190
186
]
191
187
192
- const isOptimizable = ( id : string ) =>
193
- OPTIMIZABLE_ENTRY_RE . test ( id ) ||
194
- ! ! config . optimizeDeps . extensions ?. some ( ( ext ) => id . endsWith ( ext ) )
195
-
196
188
const externalUnlessEntry = ( { path } : { path : string } ) => ( {
197
189
path,
198
190
external : ! entries . includes ( path )
@@ -235,7 +227,11 @@ function esbuildScanPlugin(
235
227
// It is possible for the scanner to scan html types in node_modules.
236
228
// If we can optimize this html type, skip it so it's handled by the
237
229
// bare import resolve, and recorded as optimization dep.
238
- if ( resolved . includes ( 'node_modules' ) && isOptimizable ( resolved ) ) return
230
+ if (
231
+ resolved . includes ( 'node_modules' ) &&
232
+ isOptimizable ( resolved , config . optimizeDeps )
233
+ )
234
+ return
239
235
return {
240
236
path : resolved ,
241
237
namespace : 'html'
@@ -382,7 +378,7 @@ function esbuildScanPlugin(
382
378
}
383
379
if ( resolved . includes ( 'node_modules' ) || include ?. includes ( id ) ) {
384
380
// dependency or forced included, externalize and stop crawling
385
- if ( isOptimizable ( resolved ) ) {
381
+ if ( isOptimizable ( resolved , config . optimizeDeps ) ) {
386
382
depImports [ id ] = resolved
387
383
}
388
384
return externalUnlessEntry ( { path : id } )
0 commit comments