Skip to content

Commit

Permalink
fix: import .css in SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
cyco130 committed Jun 28, 2022
1 parent 10936cd commit fba2ba8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export function tryNodeResolve(
// otherwise we may introduce duplicated modules for externalized files
// from pre-bundled deps.
if (!isBuild) {
const versionHash = depsOptimizer.metadata({ ssr }).browserHash
const versionHash = depsOptimizer.metadata({ ssr })?.browserHash
if (versionHash && isJsType) {
resolved = injectQuery(resolved, `v=${versionHash}`)
}
Expand Down
12 changes: 9 additions & 3 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { InternalResolveOptions } from '../plugins/resolve'
import { tryNodeResolve } from '../plugins/resolve'
import { hookNodeResolve } from '../plugins/ssrRequireHook'
import { NULL_BYTE_PLACEHOLDER } from '../constants'
import { isCSSRequest } from '../plugins/css'
import {
ssrDynamicImportKey,
ssrExportAllKey,
Expand Down Expand Up @@ -135,7 +136,10 @@ async function instantiateModule(

const ssrImport = async (dep: string) => {
if (dep[0] !== '.' && dep[0] !== '/') {
return nodeImport(dep, mod.file!, resolveOptions)
const imported = await nodeImport(dep, mod.file!, resolveOptions)
if (imported !== undefined) {
return imported
}
}
dep = unwrapId(dep)
if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) {
Expand Down Expand Up @@ -297,8 +301,10 @@ async function nodeImport(
}

try {
const mod = await dynamicImport(url)
return proxyESM(mod)
if (!isCSSRequest(url)) {
const mod = await dynamicImport(url)
return proxyESM(mod)
}
} finally {
unhookNodeResolve()
}
Expand Down

0 comments on commit fba2ba8

Please sign in to comment.