Skip to content

Commit

Permalink
fix: CSS plugin transform should call ensureEntryFromUrl() for non CS…
Browse files Browse the repository at this point in the history
…S files (fix vitejs#4150)
  • Loading branch information
paraboul committed Jul 16, 2021
1 parent 9f558ce commit 2685388
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -24,7 +24,7 @@ import {
} from 'rollup'
import { dataToEsm } from '@rollup/pluginutils'
import chalk from 'chalk'
import { CLIENT_PUBLIC_PATH } from '../constants'
import { CLIENT_PUBLIC_PATH, FS_PREFIX } from '../constants'
import { ResolveFn, ViteDevServer } from '../'
import {
getAssetFilename,
Expand Down Expand Up @@ -191,9 +191,23 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
if (deps) {
// record deps in the module graph so edits to @import css can trigger
// main import to hot update

const depModules = new Set(
[...deps].map((file) => moduleGraph.createFileOnlyEntry(file))
await Promise.all(
[...deps].map(async (file) => {
if (cssLangRE.test(file)) {
return moduleGraph.createFileOnlyEntry(file)
}

const url = file.startsWith(config.root)
? file.slice(config.root.length)
: path.posix.join(FS_PREFIX, file)

return await moduleGraph.ensureEntryFromUrl(url)
})
)
)

moduleGraph.updateModuleInfo(
thisModule,
depModules,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/moduleGraph.ts
Expand Up @@ -141,7 +141,7 @@ export class ModuleGraph {

async ensureEntryFromUrl(rawUrl: string): Promise<ModuleNode> {
const [url, resolvedId] = await this.resolveUrl(rawUrl)
let mod = this.urlToModuleMap.get(url) || this.idToModuleMap.get(resolvedId)
let mod = this.urlToModuleMap.get(url)

if (!mod) {
mod = new ModuleNode(url)
Expand Down

0 comments on commit 2685388

Please sign in to comment.