@@ -10,6 +10,16 @@ const defaultOptions = {
10
10
generateScopedName : '[name]__[local]___[hash:base64:5]'
11
11
} ;
12
12
13
+ function updateStyleSheetPath ( pathStringLiteral , importPathFormatter ) {
14
+ if ( ! importPathFormatter ) { return pathStringLiteral ; }
15
+
16
+ return {
17
+ ...pathStringLiteral ,
18
+ value : importPathFormatter ( pathStringLiteral . value )
19
+ } ;
20
+ }
21
+
22
+
13
23
function findExpressionStatementChild ( path , t ) {
14
24
const parent = path . parentPath ;
15
25
if ( ! parent ) {
@@ -113,6 +123,7 @@ export default function transformCssModules({ types: t }) {
113
123
// this is not a css-require-ook config
114
124
delete currentConfig . extractCss ;
115
125
delete currentConfig . keepImport ;
126
+ delete currentConfig . importPathFormatter ;
116
127
117
128
// match file extensions, speeds up transform by creating one
118
129
// RegExp ahead of execution time
@@ -139,6 +150,9 @@ export default function transformCssModules({ types: t }) {
139
150
Object . keys ( requireHooksOptions ) . forEach ( key => {
140
151
// skip undefined options
141
152
if ( currentConfig [ key ] === undefined ) {
153
+ if ( key === 'importPathFormatter' && thisPluginOptions && thisPluginOptions [ key ] ) {
154
+ thisPluginOptions [ key ] = requireHooksOptions [ key ] ( thisPluginOptions [ key ] ) ;
155
+ }
142
156
return ;
143
157
}
144
158
@@ -191,7 +205,7 @@ export default function transformCssModules({ types: t }) {
191
205
t . expressionStatement (
192
206
t . callExpression (
193
207
t . identifier ( 'require' ) ,
194
- [ t . stringLiteral ( value ) ]
208
+ [ updateStyleSheetPath ( t . stringLiteral ( value ) , thisPluginOptions . importPathFormatter ) ]
195
209
)
196
210
) ,
197
211
varDeclaration
@@ -227,7 +241,7 @@ export default function transformCssModules({ types: t }) {
227
241
t . expressionStatement (
228
242
t . callExpression (
229
243
t . identifier ( 'require' ) ,
230
- [ t . stringLiteral ( stylesheetPath ) ]
244
+ [ updateStyleSheetPath ( t . stringLiteral ( stylesheetPath ) , thisPluginOptions . importPathFormatter ) ]
231
245
)
232
246
)
233
247
) ;
0 commit comments