mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
25 lines
698 B
TypeScript
25 lines
698 B
TypeScript
|
import { Plugin } from 'vite'
|
||
|
import { isCSS } from '../utils'
|
||
|
|
||
|
export function devStyleSSRPlugin (rootDir: string): Plugin {
|
||
|
return {
|
||
|
name: 'nuxt:dev-style-ssr',
|
||
|
apply: 'serve',
|
||
|
enforce: 'post',
|
||
|
transform (code, id) {
|
||
|
if (!isCSS(id) || !code.includes('import.meta.hot')) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
let moduleId = id
|
||
|
if (moduleId.startsWith(rootDir)) {
|
||
|
moduleId = moduleId.slice(rootDir.length)
|
||
|
}
|
||
|
|
||
|
// When dev `<style>` is injected, remove the `<link>` styles from manifest
|
||
|
// TODO: Use `app.assetsPath` or unique hash
|
||
|
return code + `\ndocument.querySelector(\`link[href="/_nuxt${moduleId}"]\`).forEach(i=>i.remove())`
|
||
|
}
|
||
|
}
|
||
|
}
|