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: change style plugin prefix for nuxt #328

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions packages/vite-plugin/src/stylesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ function isSubdir (root: string, test: string) {
return relative && !relative.startsWith('..') && !path.isAbsolute(relative)
}

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 @@ -36,7 +40,7 @@ export function stylesPlugin (options: Options): Plugin {
)
) {
if (options.styles === 'none') {
return '\0__void__'
return `${PLUGIN_VIRTUAL_PREFIX}__void__`
} else if (options.styles === 'sass') {
const target = source.replace(/\.css$/, '.sass')
return this.resolve(target, importer, { skipSelf: true, custom })
Expand All @@ -51,25 +55,27 @@ export function stylesPlugin (options: Options): Plugin {

tempFiles.set(file, contents)

return `\0plugin-vuetify:${file}`
return `${VIRTUAL_MODULE_ID}:${file}`
}
} else if (source.startsWith('/plugin-vuetify:')) {
return '\0' + source.slice(1)
} else if (source.startsWith('/@id/__x00__plugin-vuetify:')) {
return '\0' + source.slice(12)
} else if (source.startsWith(`/${PLUGIN_VIRTUAL_NAME}:`)) {
return PLUGIN_VIRTUAL_PREFIX + source.slice(1)
} else if (source.startsWith(`/@id/__x00__${PLUGIN_VIRTUAL_NAME}:`)) {
return PLUGIN_VIRTUAL_PREFIX + source.slice(12)
} else if (source.startsWith(`/${VIRTUAL_MODULE_ID}:`)) {
return source.slice(1)
}

return null
},
load (id) {
// When Vite is configured with `optimizeDeps.exclude: ['vuetify']`, the
// received id contains a version hash (e.g. \0__void__?v=893fa859).
if (/^\0__void__(\?.*)?$/.test(id)) {
if (new RegExp(`^${PLUGIN_VIRTUAL_PREFIX}__void__(\\?.*)?$`).test(id)) {
return ''
}

if (id.startsWith('\0plugin-vuetify')) {
const file = /^\0plugin-vuetify:(.*?)(\?.*)?$/.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