4
4
*/
5
5
import path from 'path' ;
6
6
7
- import loaderUtils , {
8
- isUrlRequest ,
9
- stringifyRequest ,
10
- urlToRequest ,
11
- } from 'loader-utils' ;
7
+ import { stringifyRequest , urlToRequest , interpolateName } from 'loader-utils' ;
12
8
import normalizePath from 'normalize-path' ;
13
9
import cssesc from 'cssesc' ;
14
10
import modulesValues from 'postcss-modules-values' ;
@@ -65,8 +61,7 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
65
61
// Using `[path]` placeholder outputs `/` we need escape their
66
62
// Also directories can contains invalid characters for css we need escape their too
67
63
return cssesc (
68
- loaderUtils
69
- . interpolateName ( loaderContext , localIdentName , options )
64
+ interpolateName ( loaderContext , localIdentName , options )
70
65
// For `[hash]` placeholder
71
66
. replace ( / ^ ( ( - ? [ 0 - 9 ] ) | - - ) / , '_$1' )
72
67
. replace ( filenameReservedRegex , '-' )
@@ -216,16 +211,15 @@ function getImportCode(
216
211
let importPrefix ;
217
212
218
213
if ( exportType === 'full' ) {
214
+ const apiUrl = stringifyRequest (
215
+ loaderContext ,
216
+ require . resolve ( './runtime/api' )
217
+ ) ;
218
+
219
219
importItems . push (
220
220
esModule
221
- ? `import ___CSS_LOADER_API_IMPORT___ from ${ stringifyRequest (
222
- loaderContext ,
223
- require . resolve ( './runtime/api' )
224
- ) } ;`
225
- : `var ___CSS_LOADER_API_IMPORT___ = require(${ stringifyRequest (
226
- loaderContext ,
227
- require . resolve ( './runtime/api' )
228
- ) } );`
221
+ ? `import ___CSS_LOADER_API_IMPORT___ from ${ apiUrl } ;`
222
+ : `var ___CSS_LOADER_API_IMPORT___ = require(${ apiUrl } );`
229
223
) ;
230
224
codeItems . push (
231
225
esModule
@@ -239,10 +233,10 @@ function getImportCode(
239
233
switch ( item . type ) {
240
234
case '@import' :
241
235
{
242
- const { url, media } = item ;
236
+ const { isRequestable , url, media } = item ;
243
237
const preparedMedia = media ? `, ${ JSON . stringify ( media ) } ` : '' ;
244
238
245
- if ( ! isUrlRequest ( url ) ) {
239
+ if ( ! isRequestable ) {
246
240
codeItems . push (
247
241
`exports.push([module.id, ${ JSON . stringify (
248
242
`@import url(${ url } );`
@@ -259,17 +253,16 @@ function getImportCode(
259
253
importPrefix = getImportPrefix ( loaderContext , importLoaders ) ;
260
254
}
261
255
256
+ const importUrl = stringifyRequest (
257
+ loaderContext ,
258
+ importPrefix + url
259
+ ) ;
260
+
262
261
importName = `___CSS_LOADER_AT_RULE_IMPORT_${ atRuleImportNames . size } ___` ;
263
262
importItems . push (
264
263
esModule
265
- ? `import ${ importName } from ${ stringifyRequest (
266
- loaderContext ,
267
- importPrefix + url
268
- ) } ;`
269
- : `var ${ importName } = require(${ stringifyRequest (
270
- loaderContext ,
271
- importPrefix + url
272
- ) } );`
264
+ ? `import ${ importName } from ${ importUrl } ;`
265
+ : `var ${ importName } = require(${ importUrl } );`
273
266
) ;
274
267
275
268
atRuleImportNames . set ( url , importName ) ;
@@ -281,16 +274,15 @@ function getImportCode(
281
274
case 'url' :
282
275
{
283
276
if ( urlImportNames . size === 0 ) {
277
+ const helperUrl = stringifyRequest (
278
+ loaderContext ,
279
+ require . resolve ( './runtime/getUrl.js' )
280
+ ) ;
281
+
284
282
importItems . push (
285
283
esModule
286
- ? `import ___CSS_LOADER_GET_URL_IMPORT___ from ${ stringifyRequest (
287
- loaderContext ,
288
- require . resolve ( './runtime/getUrl.js' )
289
- ) } ;`
290
- : `var ___CSS_LOADER_GET_URL_IMPORT___ = require(${ stringifyRequest (
291
- loaderContext ,
292
- require . resolve ( './runtime/getUrl.js' )
293
- ) } );`
284
+ ? `import ___CSS_LOADER_GET_URL_IMPORT___ from ${ helperUrl } ;`
285
+ : `var ___CSS_LOADER_GET_URL_IMPORT___ = require(${ helperUrl } );`
294
286
) ;
295
287
}
296
288
@@ -299,17 +291,13 @@ function getImportCode(
299
291
let importName = urlImportNames . get ( url ) ;
300
292
301
293
if ( ! importName ) {
294
+ const importUrl = stringifyRequest ( loaderContext , url ) ;
295
+
302
296
importName = `___CSS_LOADER_URL_IMPORT_${ urlImportNames . size } ___` ;
303
297
importItems . push (
304
298
esModule
305
- ? `import ${ importName } from ${ stringifyRequest (
306
- loaderContext ,
307
- url
308
- ) } ;`
309
- : `var ${ importName } = require(${ stringifyRequest (
310
- loaderContext ,
311
- url
312
- ) } );`
299
+ ? `import ${ importName } from ${ importUrl } ;`
300
+ : `var ${ importName } = require(${ importUrl } );`
313
301
) ;
314
302
315
303
urlImportNames . set ( url , importName ) ;
@@ -335,16 +323,12 @@ function getImportCode(
335
323
importPrefix = getImportPrefix ( loaderContext , importLoaders ) ;
336
324
}
337
325
326
+ const importUrl = stringifyRequest ( loaderContext , importPrefix + url ) ;
327
+
338
328
importItems . push (
339
329
esModule
340
- ? `import ${ importName } from ${ stringifyRequest (
341
- loaderContext ,
342
- importPrefix + url
343
- ) } ;`
344
- : `var ${ importName } = require(${ stringifyRequest (
345
- loaderContext ,
346
- importPrefix + url
347
- ) } );`
330
+ ? `import ${ importName } from ${ importUrl } ;`
331
+ : `var ${ importName } = require(${ importUrl } );`
348
332
) ;
349
333
350
334
if ( exportType === 'full' ) {
0 commit comments