Skip to content

Commit

Permalink
fix(optimizer): transform css require to import (fix vitejs#12304)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day committed Mar 9, 2023
1 parent 108aadf commit b19a010
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path'
import type { ImportKind, Plugin } from 'esbuild'
import { KNOWN_ASSET_TYPES } from '../constants'
import { CSS_LANGS_RE, KNOWN_ASSET_TYPES } from '../constants'
import { getDepOptimizationConfig } from '..'
import type { ResolvedConfig } from '..'
import {
Expand Down Expand Up @@ -153,10 +153,12 @@ export function esbuildDepPlugin(
{ filter: /./, namespace: externalWithConversionNamespace },
(args) => {
// import itself with prefix (this is the actual part of require-import conversion)
const modulePath = `"${convertedExternalPrefix}${args.path}"`
return {
contents:
`export { default } from "${convertedExternalPrefix}${args.path}";` +
`export * from "${convertedExternalPrefix}${args.path}";`,
contents: CSS_LANGS_RE.test(args.path)
? `import ${modulePath};`
: `export { default } from ${modulePath};` +
`export * from ${modulePath};`,
loader: 'js',
}
},
Expand Down

0 comments on commit b19a010

Please sign in to comment.