44*/
55import path from 'path' ;
66
7- import loaderUtils , {
8- isUrlRequest ,
9- stringifyRequest ,
10- urlToRequest ,
11- } from 'loader-utils' ;
7+ import { stringifyRequest , urlToRequest , interpolateName } from 'loader-utils' ;
128import normalizePath from 'normalize-path' ;
139import cssesc from 'cssesc' ;
1410import modulesValues from 'postcss-modules-values' ;
@@ -65,8 +61,7 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
6561 // Using `[path]` placeholder outputs `/` we need escape their
6662 // Also directories can contains invalid characters for css we need escape their too
6763 return cssesc (
68- loaderUtils
69- . interpolateName ( loaderContext , localIdentName , options )
64+ interpolateName ( loaderContext , localIdentName , options )
7065 // For `[hash]` placeholder
7166 . replace ( / ^ ( ( - ? [ 0 - 9 ] ) | - - ) / , '_$1' )
7267 . replace ( filenameReservedRegex , '-' )
@@ -216,16 +211,15 @@ function getImportCode(
216211 let importPrefix ;
217212
218213 if ( exportType === 'full' ) {
214+ const apiUrl = stringifyRequest (
215+ loaderContext ,
216+ require . resolve ( './runtime/api' )
217+ ) ;
218+
219219 importItems . push (
220220 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 } );`
229223 ) ;
230224 codeItems . push (
231225 esModule
@@ -239,10 +233,10 @@ function getImportCode(
239233 switch ( item . type ) {
240234 case '@import' :
241235 {
242- const { url, media } = item ;
236+ const { isRequestable , url, media } = item ;
243237 const preparedMedia = media ? `, ${ JSON . stringify ( media ) } ` : '' ;
244238
245- if ( ! isUrlRequest ( url ) ) {
239+ if ( ! isRequestable ) {
246240 codeItems . push (
247241 `exports.push([module.id, ${ JSON . stringify (
248242 `@import url(${ url } );`
@@ -259,17 +253,16 @@ function getImportCode(
259253 importPrefix = getImportPrefix ( loaderContext , importLoaders ) ;
260254 }
261255
256+ const importUrl = stringifyRequest (
257+ loaderContext ,
258+ importPrefix + url
259+ ) ;
260+
262261 importName = `___CSS_LOADER_AT_RULE_IMPORT_${ atRuleImportNames . size } ___` ;
263262 importItems . push (
264263 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 } );`
273266 ) ;
274267
275268 atRuleImportNames . set ( url , importName ) ;
@@ -281,16 +274,15 @@ function getImportCode(
281274 case 'url' :
282275 {
283276 if ( urlImportNames . size === 0 ) {
277+ const helperUrl = stringifyRequest (
278+ loaderContext ,
279+ require . resolve ( './runtime/getUrl.js' )
280+ ) ;
281+
284282 importItems . push (
285283 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 } );`
294286 ) ;
295287 }
296288
@@ -299,17 +291,13 @@ function getImportCode(
299291 let importName = urlImportNames . get ( url ) ;
300292
301293 if ( ! importName ) {
294+ const importUrl = stringifyRequest ( loaderContext , url ) ;
295+
302296 importName = `___CSS_LOADER_URL_IMPORT_${ urlImportNames . size } ___` ;
303297 importItems . push (
304298 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 } );`
313301 ) ;
314302
315303 urlImportNames . set ( url , importName ) ;
@@ -335,16 +323,12 @@ function getImportCode(
335323 importPrefix = getImportPrefix ( loaderContext , importLoaders ) ;
336324 }
337325
326+ const importUrl = stringifyRequest ( loaderContext , importPrefix + url ) ;
327+
338328 importItems . push (
339329 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 } );`
348332 ) ;
349333
350334 if ( exportType === 'full' ) {
0 commit comments