Skip to content

Commit 633cdec

Browse files
committed
move importPrefix into separate file
allow to disable import prefix
1 parent e1c20e7 commit 633cdec

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

lib/getImportPrefix.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
module.exports = function getImportPrefix(loaderContext, query) {
6+
if(query.importLoaders === false)
7+
return "";
8+
var importLoaders = parseInt(query.importLoaders, 10) || 0;
9+
var loadersRequest = loaderContext.loaders.slice(
10+
loaderContext.loaderIndex,
11+
loaderContext.loaderIndex + 1 + importLoaders
12+
).map(function(x) { return x.request; }).join("!");
13+
return "-!" + loadersRequest + "!";
14+
};

lib/loader.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
var path = require("path");
66
var loaderUtils = require("loader-utils");
77
var processCss = require("./processCss");
8+
var getImportPrefix = require("./getImportPrefix");
89

910

1011
module.exports = function(content, map) {
1112
if(this.cacheable) this.cacheable();
1213
var query = loaderUtils.parseQuery(this.query);
1314
var root = query.root;
14-
var importLoaders = parseInt(query.importLoaders, 10) || 0;
1515
var moduleMode = query.module;
1616

1717
if(typeof map !== "string") {
@@ -30,11 +30,7 @@ module.exports = function(content, map) {
3030
var cssAsString = JSON.stringify(result.source);
3131

3232
// for importing CSS
33-
var loadersRequest = this.loaders.slice(
34-
this.loaderIndex,
35-
this.loaderIndex + 1 + importLoaders
36-
).map(function(x) { return x.request; }).join("!");
37-
var importUrlPrefix = "-!" + loadersRequest + "!";
33+
var importUrlPrefix = getImportPrefix(this, query);
3834

3935
var alreadyImported = {};
4036
var importJs = result.importItems.filter(function(imp) {

lib/localsLoader.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55
var loaderUtils = require("loader-utils");
66
var processCss = require("./processCss");
7+
var getImportPrefix = require("./getImportPrefix");
78

89

910
module.exports = function(content) {
1011
if(this.cacheable) this.cacheable();
1112
var query = loaderUtils.parseQuery(this.query);
12-
var importLoaders = parseInt(query.importLoaders, 10) || 0;
1313
var moduleMode = query.module;
1414

1515
var result = processCss(content, null, {
@@ -20,11 +20,7 @@ module.exports = function(content) {
2020
});
2121

2222
// for importing CSS
23-
var loadersRequest = this.loaders.slice(
24-
this.loaderIndex,
25-
this.loaderIndex + 1 + importLoaders
26-
).map(function(x) { return x.request; }).join("!");
27-
var importUrlPrefix = "-!" + loadersRequest + "!";
23+
var importUrlPrefix = getImportPrefix(this, query);
2824

2925
function importItemMatcher(item) {
3026
var match = result.importItemRegExp.exec(item);

0 commit comments

Comments
 (0)