-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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: css cache check #262
fix: css cache check #262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ import { | |
} from '../utils/cssUtils' | ||
import qs from 'querystring' | ||
import chalk from 'chalk' | ||
import slash from 'slash' | ||
|
||
interface ProcessedEntry { | ||
css: string | ||
|
@@ -51,25 +50,22 @@ export const cssPlugin: ServerPlugin = ({ root, app, watcher, resolver }) => { | |
} | ||
}) | ||
|
||
watcher.on('change', (file) => { | ||
/** filter unused files */ | ||
if ( | ||
!Array.from(processedCSS.keys()).some((processed) => | ||
slash(file).includes(processed) | ||
) && | ||
!srcImportMap.has(file) | ||
) { | ||
return debugCSS( | ||
`${basename(file)} has changed, but it is not currently in use` | ||
) | ||
} | ||
watcher.on('change', (filePath) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will let the mean of |
||
if (filePath.endsWith('.css') || cssPreprocessLangRE.test(filePath)) { | ||
const publicPath = resolver.fileToRequest(filePath) | ||
|
||
if (file.endsWith('.css') || cssPreprocessLangRE.test(file)) { | ||
if (srcImportMap.has(file)) { | ||
/** filter unused files */ | ||
if (!processedCSS.has(publicPath) && !srcImportMap.has(filePath)) { | ||
return debugCSS( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cache key of processedCSS.set(ctx.path, {
css: result.code,
modules: result.modules
}) |
||
`${basename(publicPath)} has changed, but it is not currently in use` | ||
) | ||
} | ||
|
||
if (srcImportMap.has(filePath)) { | ||
// handle HMR for <style src="xxx.css"> | ||
// it cannot be handled as simple css import because it may be scoped | ||
const styleImport = srcImportMap.get(file) | ||
vueCache.del(file) | ||
const styleImport = srcImportMap.get(filePath) | ||
vueCache.del(filePath) | ||
const publicPath = cleanUrl(styleImport) | ||
const index = qs.parse(styleImport.split('?', 2)[1]).index | ||
console.log( | ||
|
@@ -84,13 +80,11 @@ export const cssPlugin: ServerPlugin = ({ root, app, watcher, resolver }) => { | |
} | ||
// handle HMR for module.css | ||
// it cannot process with normal css, the class which in module.css maybe removed | ||
if (file.endsWith('.module.css')) { | ||
watcher.handleJSReload(file, Date.now()) | ||
if (filePath.endsWith('.module.css')) { | ||
watcher.handleJSReload(filePath, Date.now()) | ||
return | ||
} | ||
|
||
const publicPath = resolver.fileToRequest(file) | ||
|
||
// bust process cache | ||
processedCSS.delete(publicPath) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check the file if it is a css file first.