Skip to content

Commit

Permalink
refactor: create VIRTUAL_MODULE_ID constant for unify values
Browse files Browse the repository at this point in the history
  • Loading branch information
franz-bendezu committed Jan 7, 2024
1 parent 38b0dc1 commit 9790719
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/vite-plugin/src/stylesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function isSubdir (root: string, test: string) {

const PLUGIN_VIRTUAL_PREFIX = "virtual:"
const PLUGIN_VIRTUAL_NAME = "plugin-vuetify"
const VIRTUAL_MODULE_ID = `${PLUGIN_VIRTUAL_PREFIX}${PLUGIN_VIRTUAL_NAME}`

export function stylesPlugin (options: Options): Plugin {
const vuetifyBase = resolveVuetifyBase()
Expand Down Expand Up @@ -54,7 +55,7 @@ export function stylesPlugin (options: Options): Plugin {

tempFiles.set(file, contents)

return `${PLUGIN_VIRTUAL_PREFIX}${PLUGIN_VIRTUAL_NAME}:${file}`
return `${VIRTUAL_MODULE_ID}:${file}`
}
} else if (source.startsWith(`/${PLUGIN_VIRTUAL_NAME}:`)) {
return PLUGIN_VIRTUAL_PREFIX + source.slice(1)
Expand All @@ -71,8 +72,8 @@ export function stylesPlugin (options: Options): Plugin {
return ''
}

if (id.startsWith(`${PLUGIN_VIRTUAL_PREFIX}${PLUGIN_VIRTUAL_NAME}`)) {
const file = new RegExp(`^${PLUGIN_VIRTUAL_PREFIX}${PLUGIN_VIRTUAL_NAME}:(.*?)(\\?.*)?$`).exec(id)![1]
if (id.startsWith(`${VIRTUAL_MODULE_ID}`)) {
const file = new RegExp(`^${VIRTUAL_MODULE_ID}:(.*?)(\\?.*)?$`).exec(id)![1]

return tempFiles.get(file)
}
Expand Down

0 comments on commit 9790719

Please sign in to comment.