1
1
import path from 'node:path'
2
2
import type { ImportKind , Plugin } from 'esbuild'
3
- import { CSS_LANGS_RE , KNOWN_ASSET_TYPES } from '../constants'
3
+ import { KNOWN_ASSET_TYPES } from '../constants'
4
4
import { getDepOptimizationConfig } from '..'
5
5
import type { PackageCache , ResolvedConfig } from '..'
6
6
import {
@@ -12,6 +12,7 @@ import {
12
12
normalizePath ,
13
13
} from '../utils'
14
14
import { browserExternalId , optionalPeerDepId } from '../plugins/resolve'
15
+ import { isCSSRequest , isModuleCSSRequest } from '../plugins/css'
15
16
16
17
const externalWithConversionNamespace =
17
18
'vite:dep-pre-bundle:external-conversion'
@@ -172,10 +173,11 @@ export function esbuildDepPlugin(
172
173
// import itself with prefix (this is the actual part of require-import conversion)
173
174
const modulePath = `"${ convertedExternalPrefix } ${ args . path } "`
174
175
return {
175
- contents : CSS_LANGS_RE . test ( args . path )
176
- ? `import ${ modulePath } ;`
177
- : `export { default } from ${ modulePath } ;` +
178
- `export * from ${ modulePath } ;` ,
176
+ contents :
177
+ isCSSRequest ( args . path ) && ! isModuleCSSRequest ( args . path )
178
+ ? `import ${ modulePath } ;`
179
+ : `export { default } from ${ modulePath } ;` +
180
+ `export * from ${ modulePath } ;` ,
179
181
loader : 'js' ,
180
182
}
181
183
} ,
0 commit comments