Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call createFileOnlyEntry() only for CSS deps, fix #4150 #4267

Merged
merged 12 commits into from Jul 20, 2021
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

paraboul marked this conversation as resolved.
Show resolved Hide resolved
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)
paraboul marked this conversation as resolved.
Show resolved Hide resolved

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

paraboul marked this conversation as resolved.
Show resolved Hide resolved
moduleGraph.updateModuleInfo(
thisModule,
depModules,
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/moduleGraph.ts
Expand Up @@ -179,6 +179,7 @@ export class ModuleGraph {

const mod = new ModuleNode(url)
mod.file = file

paraboul marked this conversation as resolved.
Show resolved Hide resolved
fileMappedModules.add(mod)
return mod
}
Expand Down