1
1
import * as path from 'upath'
2
2
import { URLSearchParams } from 'url'
3
- import { writeStyles } from '@vuetify/loader-shared'
3
+ import { resolveVuetifyBase , writeStyles } from '@vuetify/loader-shared'
4
4
5
5
import type { Compiler , NormalModule , Module } from 'webpack'
6
- import type { Resolver , ResolveContext } from 'enhanced-resolve'
7
6
import type { Options } from '@vuetify/loader-shared'
8
7
9
- // Can't use require.resolve() for this, it doesn't work with resolve.symlinks
10
- let vuetifyBase : string
11
- async function getVuetifyBase ( base : string , context : ResolveContext , resolver : Resolver ) {
12
- if ( ! getVuetifyBase . promise ) {
13
- let resolve : ( v : any ) => void
14
- getVuetifyBase . promise = new Promise ( ( _resolve ) => resolve = _resolve )
15
- resolver . resolve ( { } , base , 'vuetify/package.json' , context , ( err , vuetifyPath ) => {
16
- if ( vuetifyPath ) {
17
- vuetifyBase = path . dirname ( vuetifyPath as string )
18
- }
19
- resolve ( true )
20
- } )
21
- }
22
- return getVuetifyBase . promise
23
- }
24
- getVuetifyBase . promise = null as Promise < any > | null
25
-
26
8
function isSubdir ( root : string , test : string ) {
27
9
const relative = path . relative ( root , test )
28
10
return relative && ! relative . startsWith ( '..' ) && ! path . isAbsolute ( relative )
@@ -55,6 +37,8 @@ export class VuetifyPlugin {
55
37
} )
56
38
}
57
39
40
+ const vuetifyBase = resolveVuetifyBase ( )
41
+
58
42
if (
59
43
this . options . styles === 'none' ||
60
44
this . options . styles === 'expose'
@@ -71,7 +55,7 @@ export class VuetifyPlugin {
71
55
factory . hooks . beforeResolve . tap ( 'vuetify-loader' , resolveData => {
72
56
if (
73
57
resolveData . request . endsWith ( '.css' ) &&
74
- isSubdir ( path . dirname ( require . resolve ( 'vuetify/package.json' ) ) , resolveData . context )
58
+ isSubdir ( vuetifyBase , resolveData . context )
75
59
) {
76
60
const match = resolveData . request . match ( / .* ! ( .+ \. c s s ) $ / )
77
61
if ( match ) {
@@ -156,10 +140,6 @@ export class VuetifyPlugin {
156
140
resolver
157
141
. getHook ( 'resolve' )
158
142
. tapAsync ( 'vuetify-loader' , async ( request , context , callback ) => {
159
- if ( request . path && ! vuetifyBase && request . request !== 'vuetify/package.json' ) {
160
- await getVuetifyBase ( request . path , context , resolver )
161
- }
162
-
163
143
if ( ! (
164
144
request . path &&
165
145
request . request ?. endsWith ( '.css' ) &&
0 commit comments