From 97681edc2a3412198a15d17e049e8269993347aa Mon Sep 17 00:00:00 2001 From: Code Able Date: Sat, 18 May 2024 16:48:23 +0800 Subject: [PATCH] feat: resolve vuetify base with given root --- packages/shared/src/index.ts | 6 ++++-- packages/vite-plugin/src/stylesPlugin.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index bca2c59..312e1e5 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -22,8 +22,10 @@ export type ImportPluginOptions = export { generateImports } from './imports/generateImports' -export function resolveVuetifyBase () { - return path.dirname(require.resolve('vuetify/package.json', { paths: [process.cwd()] })) +export function resolveVuetifyBase (root) { + const paths = (root && root != process.cwd()) ? [root] : []; + paths.push(process.cwd()); + return path.dirname(require.resolve('vuetify/package.json', { paths })) } export function isObject (value: any): value is object { diff --git a/packages/vite-plugin/src/stylesPlugin.ts b/packages/vite-plugin/src/stylesPlugin.ts index ba89fd5..1bd8245 100644 --- a/packages/vite-plugin/src/stylesPlugin.ts +++ b/packages/vite-plugin/src/stylesPlugin.ts @@ -10,7 +10,7 @@ function isSubdir (root: string, test: string) { } export function stylesPlugin (options: Options): Plugin { - const vuetifyBase = resolveVuetifyBase() + let vuetifyBase: string let configFile: string const tempFiles = new Map() @@ -19,11 +19,13 @@ export function stylesPlugin (options: Options): Plugin { name: 'vuetify:styles', enforce: 'pre', configResolved (config) { + const root = config.root || process.cwd(); + vuetifyBase = resolveVuetifyBase(root) if (isObject(options.styles)) { if (path.isAbsolute(options.styles.configFile)) { configFile = options.styles.configFile } else { - configFile = path.join(config.root || process.cwd(), options.styles.configFile) + configFile = path.join(root, options.styles.configFile) } } },