-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathshared.ts
More file actions
29 lines (26 loc) · 988 Bytes
/
shared.ts
File metadata and controls
29 lines (26 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
type CssVirtual = {
id: string
type: 'ssr' | 'rsc' | 'rsc-browser'
}
export function toCssVirtual({ id, type }: CssVirtual) {
// ensure other plugins treat it as a plain js file
// e.g. https://github.com/vitejs/rolldown-vite/issues/372#issuecomment-3193401601
return `virtual:vite-rsc/css?type=${type}&id=${encodeURIComponent(id)}&lang.js`
}
export function parseCssVirtual(id: string): CssVirtual | undefined {
if (id.startsWith('\0virtual:vite-rsc/css?')) {
return parseIdQuery(id).query as any
}
}
// https://github.com/vitejs/vite-plugin-vue/blob/06931b1ea2b9299267374cb8eb4db27c0626774a/packages/plugin-vue/src/utils/query.ts#L13
export function parseIdQuery(id: string): {
filename: string
query: {
[k: string]: string
}
} {
if (!id.includes('?')) return { filename: id, query: {} }
const [filename, rawQuery] = id.split(`?`, 2) as [string, string]
const query = Object.fromEntries(new URLSearchParams(rawQuery))
return { filename, query }
}