@@ -5,6 +5,7 @@ import VirtualModulesPlugin from 'webpack-virtual-modules'
5
5
import type { Compiler , WindiCSSWebpackPluginOptions } from './interfaces'
6
6
import { MODULE_ID , MODULE_ID_VIRTUAL_TEST , MODULE_ID_VIRTUAL_MODULES , NAME } from './core/constants'
7
7
import debug from './core/debug'
8
+ import { def } from './core/utils'
8
9
9
10
const loadersPath = resolve ( __dirname , 'loaders' )
10
11
const pitcher = resolve ( loadersPath , 'pitcher.js' )
@@ -28,7 +29,13 @@ class WindiCSSWebpackPlugin {
28
29
}
29
30
30
31
apply ( compiler : Compiler ) : void {
31
- const root = this . options . root ?? compiler . options . resolve ?. alias ?. [ '~' ] ?? compiler . context
32
+ // resolve the root working directory
33
+ let root = compiler . context
34
+ if ( this . options . root )
35
+ root = this . options . root
36
+ else if ( compiler . options . resolve && compiler . options . resolve . alias && compiler . options . resolve . alias [ '~' ] )
37
+ root = compiler . options . resolve . alias [ '~' ]
38
+
32
39
// Fix possibly undefined issues
33
40
if ( ! compiler . options . module || ! compiler . options . module . rules )
34
41
return
@@ -89,7 +96,7 @@ class WindiCSSWebpackPlugin {
89
96
if ( shouldExcludeResource ( resource ) )
90
97
return false
91
98
92
- return Boolean ( compiler . $windyCSSService ? .isDetectTarget ( resource ) )
99
+ return Boolean ( compiler . $windyCSSService . isDetectTarget ( resource ) )
93
100
} ,
94
101
enforce : 'post' ,
95
102
use : [ {
@@ -107,7 +114,7 @@ class WindiCSSWebpackPlugin {
107
114
if ( shouldExcludeResource ( resource ) )
108
115
return false
109
116
110
- return Boolean ( compiler . $windyCSSService ? .isDetectTarget ( resource ) )
117
+ return Boolean ( compiler . $windyCSSService . isDetectTarget ( resource ) )
111
118
} ,
112
119
use : [ {
113
120
loader : transformTemplateLoader ,
@@ -119,7 +126,7 @@ class WindiCSSWebpackPlugin {
119
126
if ( shouldExcludeResource ( resource ) )
120
127
return false
121
128
122
- return Boolean ( compiler . $windyCSSService ? .isCssTransformTarget ( resource ) )
129
+ return Boolean ( compiler . $windyCSSService . isCssTransformTarget ( resource ) )
123
130
} ,
124
131
use : [ {
125
132
loader : transformCSSLoader ,
@@ -204,7 +211,7 @@ class WindiCSSWebpackPlugin {
204
211
if ( match ) {
205
212
const layer = ( match [ 1 ] as LayerName | 'all' ) || 'all'
206
213
if ( compiler . $windyCSSService && compiler . $windyCSSService . virtualModules . has ( layer ) )
207
- virtualModuleContent = compiler . $windyCSSService . virtualModules . get ( layer ) ?? ''
214
+ virtualModuleContent = def ( compiler . $windyCSSService . virtualModules . get ( layer ) , '' )
208
215
}
209
216
virtualModules . writeModule (
210
217
join ( this . options . virtualModulePath , virtualModulePath ) ,
@@ -217,10 +224,10 @@ class WindiCSSWebpackPlugin {
217
224
// Make windy service available to the loader
218
225
const initWindyCSSService = async ( ) => {
219
226
if ( ! compiler . $windyCSSService ) {
220
- const utils = this . options . utils ?? createUtils ( this . options , {
227
+ const utils = def ( this . options . utils , createUtils ( this . options , {
221
228
root,
222
229
name : NAME ,
223
- } )
230
+ } ) )
224
231
225
232
compiler . $windyCSSService = Object . assign (
226
233
utils ,
0 commit comments