css-loader 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +10 -10
- package/.github/ISSUE_TEMPLATE.md +15 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +18 -0
- package/.travis.yml +12 -12
- package/README.md +24 -3
- package/index.js +5 -5
- package/lib/compile-exports.js +29 -29
- package/lib/css-base.js +50 -50
- package/lib/getImportPrefix.js +14 -14
- package/lib/getLocalIdent.js +16 -16
- package/lib/loader.js +124 -124
- package/lib/localsLoader.js +46 -46
- package/lib/processCss.js +252 -251
- package/locals.js +5 -5
- package/package.json +1 -1
package/.eslintrc
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true
|
|
4
|
-
},
|
|
5
|
-
"rules": {
|
|
6
|
-
"strict": 0,
|
|
7
|
-
"curly": 0,
|
|
8
|
-
"quotes": 0
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true
|
|
4
|
+
},
|
|
5
|
+
"rules": {
|
|
6
|
+
"strict": 0,
|
|
7
|
+
"curly": 0,
|
|
8
|
+
"quotes": 0
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!-- Before creating an issue please make sure you are using the latest version of css-loader. -->
|
|
2
|
+
|
|
3
|
+
**Do you want to request a *feature* or report a *bug*?**
|
|
4
|
+
<!-- Please ask questions on StackOverflow or the webpack Gitter (https://gitter.im/webpack/webpack). Questions will be closed. -->
|
|
5
|
+
|
|
6
|
+
**What is the current behavior?**
|
|
7
|
+
|
|
8
|
+
**If the current behavior is a bug, please provide the steps to reproduce.**
|
|
9
|
+
<!-- A great way to do this is to provide your configuration via a GitHub gist. -->
|
|
10
|
+
|
|
11
|
+
**What is the expected behavior?**
|
|
12
|
+
|
|
13
|
+
**If this is a feature request, what is motivation or use case for changing the behavior?**
|
|
14
|
+
|
|
15
|
+
**Please mention other relevant information such as your webpack version, Node.js version and Operating System.**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->
|
|
2
|
+
|
|
3
|
+
**What kind of change does this PR introduce?**
|
|
4
|
+
<!-- E.g. a bugfix, feature, refactoring, build related change, etc… -->
|
|
5
|
+
|
|
6
|
+
**Did you add tests for your changes?**
|
|
7
|
+
|
|
8
|
+
**If relevant, did you update the README?**
|
|
9
|
+
|
|
10
|
+
**Summary**
|
|
11
|
+
|
|
12
|
+
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
|
|
13
|
+
<!-- Try to link to an open issue for more information. -->
|
|
14
|
+
|
|
15
|
+
**Does this PR introduce a breaking change?**
|
|
16
|
+
<!-- If this PR introduces a breaking change, please describe the impact and a migration path for existing applications. -->
|
|
17
|
+
|
|
18
|
+
**Other information**
|
package/.travis.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
language: node_js
|
|
3
|
-
node_js:
|
|
4
|
-
- "0.12"
|
|
5
|
-
- "node"
|
|
6
|
-
- "iojs"
|
|
7
|
-
script: npm run travis
|
|
8
|
-
|
|
9
|
-
after_success:
|
|
10
|
-
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
|
|
11
|
-
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
|
|
12
|
-
- rm -rf ./coverage
|
|
1
|
+
sudo: false
|
|
2
|
+
language: node_js
|
|
3
|
+
node_js:
|
|
4
|
+
- "0.12"
|
|
5
|
+
- "node"
|
|
6
|
+
- "iojs"
|
|
7
|
+
script: npm run travis
|
|
8
|
+
|
|
9
|
+
after_success:
|
|
10
|
+
- cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose
|
|
11
|
+
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
|
|
12
|
+
- rm -rf ./coverage
|
package/README.md
CHANGED
|
@@ -108,6 +108,27 @@ You can use `:local(#someId)`, but this is not recommended. Use classes instead
|
|
|
108
108
|
|
|
109
109
|
You can configure the generated ident with the `localIdentName` query parameter (default `[hash:base64]`). Example: `css-loader?localIdentName=[path][name]---[local]---[hash:base64:5]` for easier debugging.
|
|
110
110
|
|
|
111
|
+
You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema. Note that this requires `webpack@2` since to be able to pass function in. For example:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
{
|
|
115
|
+
test: /\.css$/,
|
|
116
|
+
loaders: [
|
|
117
|
+
{
|
|
118
|
+
loader: 'css-loader',
|
|
119
|
+
query: {
|
|
120
|
+
modules: true,
|
|
121
|
+
importLoaders: 1,
|
|
122
|
+
getLocalIdent: function (loaderContext, localIdentName, localName, options) {
|
|
123
|
+
return 'whatever_random_class_name'
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
111
132
|
Note: For prerendering with extract-text-webpack-plugin you should use `css-loader/locals` instead of `style-loader!css-loader` **in the prerendering bundle**. It doesn't embed CSS but only exports the identifier mappings.
|
|
112
133
|
|
|
113
134
|
### CSS Modules
|
|
@@ -204,9 +225,9 @@ The query parameter `importLoaders` allow to configure which loaders should be a
|
|
|
204
225
|
Examples:
|
|
205
226
|
|
|
206
227
|
``` js
|
|
207
|
-
require("style-loader!css-loader?importLoaders=1!
|
|
228
|
+
require("style-loader!css-loader?importLoaders=1!postcss-loader!...")
|
|
208
229
|
// => imported resources are handled this way:
|
|
209
|
-
require("css-loader?importLoaders=1!
|
|
230
|
+
require("css-loader?importLoaders=1!postcss-loader!...")
|
|
210
231
|
|
|
211
232
|
require("style-loader!css-loader!stylus-loader!...")
|
|
212
233
|
// => imported resources are handled this way:
|
|
@@ -219,7 +240,7 @@ This may change in the future, when the module system (i. e. webpack) supports l
|
|
|
219
240
|
|
|
220
241
|
By default the css-loader minimizes the css if specified by the module system.
|
|
221
242
|
|
|
222
|
-
In some cases the minification is destructive to the css, so you can provide some options to it. cssnano is used for minification and you find a [list of options here](http://cssnano.co/options/). Just provide them as query parameter: i. e. `require("css-loader?-
|
|
243
|
+
In some cases the minification is destructive to the css, so you can provide some options to it. cssnano is used for minification and you find a [list of options here](http://cssnano.co/options/). Just provide them as query parameter: i. e. `require("css-loader?-colormin")` to disable making color values as small as possible.
|
|
223
244
|
|
|
224
245
|
You can also disable or enforce minification with the `minimize` query parameter.
|
|
225
246
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
module.exports = require("./lib/loader");
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
module.exports = require("./lib/loader");
|
package/lib/compile-exports.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
var camelCase = require("lodash.camelcase");
|
|
2
|
-
|
|
3
|
-
function dashesCamelCase(str) {
|
|
4
|
-
return str.replace(/-(\w)/g, function(match, firstLetter) {
|
|
5
|
-
return firstLetter.toUpperCase();
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) {
|
|
10
|
-
if (!Object.keys(result.exports).length) {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
var exportJs = Object.keys(result.exports).reduce(function(res, key) {
|
|
15
|
-
var valueAsString = JSON.stringify(result.exports[key]);
|
|
16
|
-
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
|
|
17
|
-
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
|
|
18
|
-
|
|
19
|
-
if (camelCaseKeys === true) {
|
|
20
|
-
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
|
|
21
|
-
} else if (camelCaseKeys === 'dashes') {
|
|
22
|
-
res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return res;
|
|
26
|
-
}, []).join(",\n");
|
|
27
|
-
|
|
28
|
-
return "{\n" + exportJs + "\n}";
|
|
29
|
-
};
|
|
1
|
+
var camelCase = require("lodash.camelcase");
|
|
2
|
+
|
|
3
|
+
function dashesCamelCase(str) {
|
|
4
|
+
return str.replace(/-(\w)/g, function(match, firstLetter) {
|
|
5
|
+
return firstLetter.toUpperCase();
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) {
|
|
10
|
+
if (!Object.keys(result.exports).length) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var exportJs = Object.keys(result.exports).reduce(function(res, key) {
|
|
15
|
+
var valueAsString = JSON.stringify(result.exports[key]);
|
|
16
|
+
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
|
|
17
|
+
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
|
|
18
|
+
|
|
19
|
+
if (camelCaseKeys === true) {
|
|
20
|
+
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
|
|
21
|
+
} else if (camelCaseKeys === 'dashes') {
|
|
22
|
+
res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return res;
|
|
26
|
+
}, []).join(",\n");
|
|
27
|
+
|
|
28
|
+
return "{\n" + exportJs + "\n}";
|
|
29
|
+
};
|
package/lib/css-base.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
// css base code, injected by the css-loader
|
|
6
|
-
module.exports = function() {
|
|
7
|
-
var list = [];
|
|
8
|
-
|
|
9
|
-
// return the list of modules as css string
|
|
10
|
-
list.toString = function toString() {
|
|
11
|
-
var result = [];
|
|
12
|
-
for(var i = 0; i < this.length; i++) {
|
|
13
|
-
var item = this[i];
|
|
14
|
-
if(item[2]) {
|
|
15
|
-
result.push("@media " + item[2] + "{" + item[1] + "}");
|
|
16
|
-
} else {
|
|
17
|
-
result.push(item[1]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return result.join("");
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// import a list of modules into the list
|
|
24
|
-
list.i = function(modules, mediaQuery) {
|
|
25
|
-
if(typeof modules === "string")
|
|
26
|
-
modules = [[null, modules, ""]];
|
|
27
|
-
var alreadyImportedModules = {};
|
|
28
|
-
for(var i = 0; i < this.length; i++) {
|
|
29
|
-
var id = this[i][0];
|
|
30
|
-
if(typeof id === "number")
|
|
31
|
-
alreadyImportedModules[id] = true;
|
|
32
|
-
}
|
|
33
|
-
for(i = 0; i < modules.length; i++) {
|
|
34
|
-
var item = modules[i];
|
|
35
|
-
// skip already imported module
|
|
36
|
-
// this implementation is not 100% perfect for weird media query combinations
|
|
37
|
-
// when a module is imported multiple times with different media queries.
|
|
38
|
-
// I hope this will never occur (Hey this way we have smaller bundles)
|
|
39
|
-
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
|
|
40
|
-
if(mediaQuery && !item[2]) {
|
|
41
|
-
item[2] = mediaQuery;
|
|
42
|
-
} else if(mediaQuery) {
|
|
43
|
-
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
|
|
44
|
-
}
|
|
45
|
-
list.push(item);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
return list;
|
|
50
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
// css base code, injected by the css-loader
|
|
6
|
+
module.exports = function() {
|
|
7
|
+
var list = [];
|
|
8
|
+
|
|
9
|
+
// return the list of modules as css string
|
|
10
|
+
list.toString = function toString() {
|
|
11
|
+
var result = [];
|
|
12
|
+
for(var i = 0; i < this.length; i++) {
|
|
13
|
+
var item = this[i];
|
|
14
|
+
if(item[2]) {
|
|
15
|
+
result.push("@media " + item[2] + "{" + item[1] + "}");
|
|
16
|
+
} else {
|
|
17
|
+
result.push(item[1]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result.join("");
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// import a list of modules into the list
|
|
24
|
+
list.i = function(modules, mediaQuery) {
|
|
25
|
+
if(typeof modules === "string")
|
|
26
|
+
modules = [[null, modules, ""]];
|
|
27
|
+
var alreadyImportedModules = {};
|
|
28
|
+
for(var i = 0; i < this.length; i++) {
|
|
29
|
+
var id = this[i][0];
|
|
30
|
+
if(typeof id === "number")
|
|
31
|
+
alreadyImportedModules[id] = true;
|
|
32
|
+
}
|
|
33
|
+
for(i = 0; i < modules.length; i++) {
|
|
34
|
+
var item = modules[i];
|
|
35
|
+
// skip already imported module
|
|
36
|
+
// this implementation is not 100% perfect for weird media query combinations
|
|
37
|
+
// when a module is imported multiple times with different media queries.
|
|
38
|
+
// I hope this will never occur (Hey this way we have smaller bundles)
|
|
39
|
+
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
|
|
40
|
+
if(mediaQuery && !item[2]) {
|
|
41
|
+
item[2] = mediaQuery;
|
|
42
|
+
} else if(mediaQuery) {
|
|
43
|
+
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
|
|
44
|
+
}
|
|
45
|
+
list.push(item);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return list;
|
|
50
|
+
};
|
package/lib/getImportPrefix.js
CHANGED
|
@@ -1,14 +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
|
-
};
|
|
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
|
+
};
|
package/lib/getLocalIdent.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var loaderUtils = require("loader-utils");
|
|
6
|
-
var path = require("path");
|
|
7
|
-
|
|
8
|
-
module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
9
|
-
if(!options.context)
|
|
10
|
-
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
|
|
11
|
-
var request = path.relative(options.context, loaderContext.resourcePath);
|
|
12
|
-
options.content = options.hashPrefix + request + "+" + localName;
|
|
13
|
-
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
|
|
14
|
-
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
|
|
15
|
-
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
|
|
16
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
var loaderUtils = require("loader-utils");
|
|
6
|
+
var path = require("path");
|
|
7
|
+
|
|
8
|
+
module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
9
|
+
if(!options.context)
|
|
10
|
+
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
|
|
11
|
+
var request = path.relative(options.context, loaderContext.resourcePath);
|
|
12
|
+
options.content = options.hashPrefix + request + "+" + localName;
|
|
13
|
+
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
|
|
14
|
+
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
|
|
15
|
+
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
|
|
16
|
+
};
|
package/lib/loader.js
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var path = require("path");
|
|
6
|
-
var loaderUtils = require("loader-utils");
|
|
7
|
-
var processCss = require("./processCss");
|
|
8
|
-
var getImportPrefix = require("./getImportPrefix");
|
|
9
|
-
var compileExports = require("./compile-exports");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module.exports = function(content, map) {
|
|
13
|
-
if(this.cacheable) this.cacheable();
|
|
14
|
-
var callback = this.async();
|
|
15
|
-
var query = loaderUtils.parseQuery(this.query);
|
|
16
|
-
var root = query.root;
|
|
17
|
-
var moduleMode = query.modules || query.module;
|
|
18
|
-
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
19
|
-
|
|
20
|
-
if(map !== null && typeof map !== "string") {
|
|
21
|
-
map = JSON.stringify(map);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
processCss(content, map, {
|
|
25
|
-
mode: moduleMode ? "local" : "global",
|
|
26
|
-
from: loaderUtils.getRemainingRequest(this),
|
|
27
|
-
to: loaderUtils.getCurrentRequest(this),
|
|
28
|
-
query: query,
|
|
29
|
-
minimize: this.minimize,
|
|
30
|
-
loaderContext: this
|
|
31
|
-
}, function(err, result) {
|
|
32
|
-
if(err) return callback(err);
|
|
33
|
-
|
|
34
|
-
var cssAsString = JSON.stringify(result.source);
|
|
35
|
-
|
|
36
|
-
// for importing CSS
|
|
37
|
-
var importUrlPrefix = getImportPrefix(this, query);
|
|
38
|
-
|
|
39
|
-
var alreadyImported = {};
|
|
40
|
-
var importJs = result.importItems.filter(function(imp) {
|
|
41
|
-
if(!imp.mediaQuery) {
|
|
42
|
-
if(alreadyImported[imp.url])
|
|
43
|
-
return false;
|
|
44
|
-
alreadyImported[imp.url] = true;
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
}).map(function(imp) {
|
|
48
|
-
if(!loaderUtils.isUrlRequest(imp.url, root)) {
|
|
49
|
-
return "exports.push([module.id, " +
|
|
50
|
-
JSON.stringify("@import url(" + imp.url + ");") + ", " +
|
|
51
|
-
JSON.stringify(imp.mediaQuery) + "]);";
|
|
52
|
-
} else {
|
|
53
|
-
var importUrl = importUrlPrefix + imp.url;
|
|
54
|
-
return "exports.i(require(" + loaderUtils.stringifyRequest(this, importUrl) + "), " + JSON.stringify(imp.mediaQuery) + ");";
|
|
55
|
-
}
|
|
56
|
-
}, this).join("\n");
|
|
57
|
-
|
|
58
|
-
function importItemMatcher(item) {
|
|
59
|
-
var match = result.importItemRegExp.exec(item);
|
|
60
|
-
var idx = +match[1];
|
|
61
|
-
var importItem = result.importItems[idx];
|
|
62
|
-
var importUrl = importUrlPrefix + importItem.url;
|
|
63
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ").locals" +
|
|
64
|
-
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
|
|
68
|
-
if(query.url !== false) {
|
|
69
|
-
cssAsString = cssAsString.replace(result.urlItemRegExpG, function(item) {
|
|
70
|
-
var match = result.urlItemRegExp.exec(item);
|
|
71
|
-
var idx = +match[1];
|
|
72
|
-
var urlItem = result.urlItems[idx];
|
|
73
|
-
var url = urlItem.url;
|
|
74
|
-
idx = url.indexOf("?#");
|
|
75
|
-
if(idx < 0) idx = url.indexOf("#");
|
|
76
|
-
var urlRequest;
|
|
77
|
-
if(idx > 0) { // idx === 0 is catched by isUrlRequest
|
|
78
|
-
// in cases like url('webfont.eot?#iefix')
|
|
79
|
-
urlRequest = url.substr(0, idx);
|
|
80
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"" +
|
|
81
|
-
url.substr(idx);
|
|
82
|
-
}
|
|
83
|
-
urlRequest = url;
|
|
84
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
|
|
85
|
-
}.bind(this));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
90
|
-
if (exportJs) {
|
|
91
|
-
exportJs = "exports.locals = " + exportJs + ";";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
var moduleJs;
|
|
95
|
-
if(query.sourceMap && result.map) {
|
|
96
|
-
// add a SourceMap
|
|
97
|
-
map = result.map;
|
|
98
|
-
if(map.sources) {
|
|
99
|
-
map.sources = map.sources.map(function(source) {
|
|
100
|
-
source = source.split("!").pop();
|
|
101
|
-
var p = path.relative(query.context || this.options.context, source).replace(/\\/g, "/");
|
|
102
|
-
if(p.indexOf("../") !== 0)
|
|
103
|
-
p = "./" + p;
|
|
104
|
-
return "/" + p;
|
|
105
|
-
}, this);
|
|
106
|
-
map.sourceRoot = "webpack://";
|
|
107
|
-
}
|
|
108
|
-
map.file = map.file.split("!").pop();
|
|
109
|
-
map = JSON.stringify(map);
|
|
110
|
-
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\", " + map + "]);";
|
|
111
|
-
} else {
|
|
112
|
-
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\"]);";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// embed runtime
|
|
116
|
-
callback(null, "exports = module.exports = require(" + loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) + ")();\n" +
|
|
117
|
-
"// imports\n" +
|
|
118
|
-
importJs + "\n\n" +
|
|
119
|
-
"// module\n" +
|
|
120
|
-
moduleJs + "\n\n" +
|
|
121
|
-
"// exports\n" +
|
|
122
|
-
exportJs);
|
|
123
|
-
}.bind(this));
|
|
124
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
var path = require("path");
|
|
6
|
+
var loaderUtils = require("loader-utils");
|
|
7
|
+
var processCss = require("./processCss");
|
|
8
|
+
var getImportPrefix = require("./getImportPrefix");
|
|
9
|
+
var compileExports = require("./compile-exports");
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
module.exports = function(content, map) {
|
|
13
|
+
if(this.cacheable) this.cacheable();
|
|
14
|
+
var callback = this.async();
|
|
15
|
+
var query = loaderUtils.parseQuery(this.query);
|
|
16
|
+
var root = query.root;
|
|
17
|
+
var moduleMode = query.modules || query.module;
|
|
18
|
+
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
19
|
+
|
|
20
|
+
if(map !== null && typeof map !== "string") {
|
|
21
|
+
map = JSON.stringify(map);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
processCss(content, map, {
|
|
25
|
+
mode: moduleMode ? "local" : "global",
|
|
26
|
+
from: loaderUtils.getRemainingRequest(this),
|
|
27
|
+
to: loaderUtils.getCurrentRequest(this),
|
|
28
|
+
query: query,
|
|
29
|
+
minimize: this.minimize,
|
|
30
|
+
loaderContext: this
|
|
31
|
+
}, function(err, result) {
|
|
32
|
+
if(err) return callback(err);
|
|
33
|
+
|
|
34
|
+
var cssAsString = JSON.stringify(result.source);
|
|
35
|
+
|
|
36
|
+
// for importing CSS
|
|
37
|
+
var importUrlPrefix = getImportPrefix(this, query);
|
|
38
|
+
|
|
39
|
+
var alreadyImported = {};
|
|
40
|
+
var importJs = result.importItems.filter(function(imp) {
|
|
41
|
+
if(!imp.mediaQuery) {
|
|
42
|
+
if(alreadyImported[imp.url])
|
|
43
|
+
return false;
|
|
44
|
+
alreadyImported[imp.url] = true;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}).map(function(imp) {
|
|
48
|
+
if(!loaderUtils.isUrlRequest(imp.url, root)) {
|
|
49
|
+
return "exports.push([module.id, " +
|
|
50
|
+
JSON.stringify("@import url(" + imp.url + ");") + ", " +
|
|
51
|
+
JSON.stringify(imp.mediaQuery) + "]);";
|
|
52
|
+
} else {
|
|
53
|
+
var importUrl = importUrlPrefix + imp.url;
|
|
54
|
+
return "exports.i(require(" + loaderUtils.stringifyRequest(this, importUrl) + "), " + JSON.stringify(imp.mediaQuery) + ");";
|
|
55
|
+
}
|
|
56
|
+
}, this).join("\n");
|
|
57
|
+
|
|
58
|
+
function importItemMatcher(item) {
|
|
59
|
+
var match = result.importItemRegExp.exec(item);
|
|
60
|
+
var idx = +match[1];
|
|
61
|
+
var importItem = result.importItems[idx];
|
|
62
|
+
var importUrl = importUrlPrefix + importItem.url;
|
|
63
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ").locals" +
|
|
64
|
+
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
|
|
68
|
+
if(query.url !== false) {
|
|
69
|
+
cssAsString = cssAsString.replace(result.urlItemRegExpG, function(item) {
|
|
70
|
+
var match = result.urlItemRegExp.exec(item);
|
|
71
|
+
var idx = +match[1];
|
|
72
|
+
var urlItem = result.urlItems[idx];
|
|
73
|
+
var url = urlItem.url;
|
|
74
|
+
idx = url.indexOf("?#");
|
|
75
|
+
if(idx < 0) idx = url.indexOf("#");
|
|
76
|
+
var urlRequest;
|
|
77
|
+
if(idx > 0) { // idx === 0 is catched by isUrlRequest
|
|
78
|
+
// in cases like url('webfont.eot?#iefix')
|
|
79
|
+
urlRequest = url.substr(0, idx);
|
|
80
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"" +
|
|
81
|
+
url.substr(idx);
|
|
82
|
+
}
|
|
83
|
+
urlRequest = url;
|
|
84
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
|
|
85
|
+
}.bind(this));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
90
|
+
if (exportJs) {
|
|
91
|
+
exportJs = "exports.locals = " + exportJs + ";";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var moduleJs;
|
|
95
|
+
if(query.sourceMap && result.map) {
|
|
96
|
+
// add a SourceMap
|
|
97
|
+
map = result.map;
|
|
98
|
+
if(map.sources) {
|
|
99
|
+
map.sources = map.sources.map(function(source) {
|
|
100
|
+
source = source.split("!").pop();
|
|
101
|
+
var p = path.relative(query.context || this.options.context, source).replace(/\\/g, "/");
|
|
102
|
+
if(p.indexOf("../") !== 0)
|
|
103
|
+
p = "./" + p;
|
|
104
|
+
return "/" + p;
|
|
105
|
+
}, this);
|
|
106
|
+
map.sourceRoot = "webpack://";
|
|
107
|
+
}
|
|
108
|
+
map.file = map.file.split("!").pop();
|
|
109
|
+
map = JSON.stringify(map);
|
|
110
|
+
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\", " + map + "]);";
|
|
111
|
+
} else {
|
|
112
|
+
moduleJs = "exports.push([module.id, " + cssAsString + ", \"\"]);";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// embed runtime
|
|
116
|
+
callback(null, "exports = module.exports = require(" + loaderUtils.stringifyRequest(this, require.resolve("./css-base.js")) + ")();\n" +
|
|
117
|
+
"// imports\n" +
|
|
118
|
+
importJs + "\n\n" +
|
|
119
|
+
"// module\n" +
|
|
120
|
+
moduleJs + "\n\n" +
|
|
121
|
+
"// exports\n" +
|
|
122
|
+
exportJs);
|
|
123
|
+
}.bind(this));
|
|
124
|
+
};
|
package/lib/localsLoader.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var loaderUtils = require("loader-utils");
|
|
6
|
-
var processCss = require("./processCss");
|
|
7
|
-
var getImportPrefix = require("./getImportPrefix");
|
|
8
|
-
var compileExports = require("./compile-exports");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = function(content) {
|
|
12
|
-
if(this.cacheable) this.cacheable();
|
|
13
|
-
var callback = this.async();
|
|
14
|
-
var query = loaderUtils.parseQuery(this.query);
|
|
15
|
-
var moduleMode = query.modules || query.module;
|
|
16
|
-
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
17
|
-
|
|
18
|
-
processCss(content, null, {
|
|
19
|
-
mode: moduleMode ? "local" : "global",
|
|
20
|
-
query: query,
|
|
21
|
-
minimize: this.minimize,
|
|
22
|
-
loaderContext: this
|
|
23
|
-
}, function(err, result) {
|
|
24
|
-
if(err) return callback(err);
|
|
25
|
-
|
|
26
|
-
// for importing CSS
|
|
27
|
-
var importUrlPrefix = getImportPrefix(this, query);
|
|
28
|
-
|
|
29
|
-
function importItemMatcher(item) {
|
|
30
|
-
var match = result.importItemRegExp.exec(item);
|
|
31
|
-
var idx = +match[1];
|
|
32
|
-
var importItem = result.importItems[idx];
|
|
33
|
-
var importUrl = importUrlPrefix + importItem.url;
|
|
34
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ")" +
|
|
35
|
-
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
39
|
-
if (exportJs) {
|
|
40
|
-
exportJs = "module.exports = " + exportJs + ";";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
callback(null, exportJs);
|
|
45
|
-
}.bind(this));
|
|
46
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
var loaderUtils = require("loader-utils");
|
|
6
|
+
var processCss = require("./processCss");
|
|
7
|
+
var getImportPrefix = require("./getImportPrefix");
|
|
8
|
+
var compileExports = require("./compile-exports");
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
module.exports = function(content) {
|
|
12
|
+
if(this.cacheable) this.cacheable();
|
|
13
|
+
var callback = this.async();
|
|
14
|
+
var query = loaderUtils.parseQuery(this.query);
|
|
15
|
+
var moduleMode = query.modules || query.module;
|
|
16
|
+
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
17
|
+
|
|
18
|
+
processCss(content, null, {
|
|
19
|
+
mode: moduleMode ? "local" : "global",
|
|
20
|
+
query: query,
|
|
21
|
+
minimize: this.minimize,
|
|
22
|
+
loaderContext: this
|
|
23
|
+
}, function(err, result) {
|
|
24
|
+
if(err) return callback(err);
|
|
25
|
+
|
|
26
|
+
// for importing CSS
|
|
27
|
+
var importUrlPrefix = getImportPrefix(this, query);
|
|
28
|
+
|
|
29
|
+
function importItemMatcher(item) {
|
|
30
|
+
var match = result.importItemRegExp.exec(item);
|
|
31
|
+
var idx = +match[1];
|
|
32
|
+
var importItem = result.importItems[idx];
|
|
33
|
+
var importUrl = importUrlPrefix + importItem.url;
|
|
34
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, importUrl) + ")" +
|
|
35
|
+
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
39
|
+
if (exportJs) {
|
|
40
|
+
exportJs = "module.exports = " + exportJs + ";";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
callback(null, exportJs);
|
|
45
|
+
}.bind(this));
|
|
46
|
+
};
|
package/lib/processCss.js
CHANGED
|
@@ -1,251 +1,252 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
var formatCodeFrame = require("babel-code-frame");
|
|
6
|
-
var Tokenizer = require("css-selector-tokenizer");
|
|
7
|
-
var postcss = require("postcss");
|
|
8
|
-
var loaderUtils = require("loader-utils");
|
|
9
|
-
var assign = require("object-assign");
|
|
10
|
-
var getLocalIdent = require("./getLocalIdent");
|
|
11
|
-
|
|
12
|
-
var localByDefault = require("postcss-modules-local-by-default");
|
|
13
|
-
var extractImports = require("postcss-modules-extract-imports");
|
|
14
|
-
var modulesScope = require("postcss-modules-scope");
|
|
15
|
-
var modulesValues = require("postcss-modules-values");
|
|
16
|
-
var cssnano = require("cssnano");
|
|
17
|
-
|
|
18
|
-
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
19
|
-
return function(css) {
|
|
20
|
-
var imports = {};
|
|
21
|
-
var exports = {};
|
|
22
|
-
var importItems = [];
|
|
23
|
-
var urlItems = [];
|
|
24
|
-
|
|
25
|
-
function replaceImportsInString(str) {
|
|
26
|
-
if(options.import) {
|
|
27
|
-
var tokens = str.split(/(\S+)/);
|
|
28
|
-
tokens = tokens.map(function (token) {
|
|
29
|
-
var importIndex = imports["$" + token];
|
|
30
|
-
if(typeof importIndex === "number") {
|
|
31
|
-
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
32
|
-
}
|
|
33
|
-
return token;
|
|
34
|
-
});
|
|
35
|
-
return tokens.join("");
|
|
36
|
-
}
|
|
37
|
-
return str;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if(options.import) {
|
|
41
|
-
css.walkAtRules("import", function(rule) {
|
|
42
|
-
var values = Tokenizer.parseValues(rule.params);
|
|
43
|
-
var url = values.nodes[0].nodes[0];
|
|
44
|
-
if(url.type === "url") {
|
|
45
|
-
url = url.url;
|
|
46
|
-
} else if(url.type === "string") {
|
|
47
|
-
url = url.value;
|
|
48
|
-
} else throw rule.error("Unexpected format" + rule.params);
|
|
49
|
-
values.nodes[0].nodes.shift();
|
|
50
|
-
var mediaQuery = Tokenizer.stringifyValues(values);
|
|
51
|
-
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
|
|
52
|
-
url = loaderUtils.urlToRequest(url, options.root);
|
|
53
|
-
}
|
|
54
|
-
importItems.push({
|
|
55
|
-
url: url,
|
|
56
|
-
mediaQuery: mediaQuery
|
|
57
|
-
});
|
|
58
|
-
rule.remove();
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
css.walkRules(function(rule) {
|
|
63
|
-
if(rule.selector === ":export") {
|
|
64
|
-
rule.walkDecls(function(decl) {
|
|
65
|
-
exports[decl.prop] = decl.value;
|
|
66
|
-
});
|
|
67
|
-
rule.remove();
|
|
68
|
-
} else if(/^:import\(.+\)$/.test(rule.selector)) {
|
|
69
|
-
var match = /^:import\((.+)\)$/.exec(rule.selector);
|
|
70
|
-
var url = loaderUtils.parseString(match[1]);
|
|
71
|
-
rule.walkDecls(function(decl) {
|
|
72
|
-
imports["$" + decl.prop] = importItems.length;
|
|
73
|
-
importItems.push({
|
|
74
|
-
url: url,
|
|
75
|
-
export: decl.value
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
rule.remove();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
Object.keys(exports).forEach(function(exportName) {
|
|
83
|
-
exports[exportName] = replaceImportsInString(exports[exportName]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
function processNode(item) {
|
|
87
|
-
switch (item.type) {
|
|
88
|
-
case "value":
|
|
89
|
-
item.nodes.forEach(processNode);
|
|
90
|
-
break;
|
|
91
|
-
case "nested-item":
|
|
92
|
-
item.nodes.forEach(processNode);
|
|
93
|
-
break;
|
|
94
|
-
case "item":
|
|
95
|
-
var importIndex = imports["$" + item.name];
|
|
96
|
-
if (typeof importIndex === "number") {
|
|
97
|
-
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
case "url":
|
|
101
|
-
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
|
|
102
|
-
item.stringType = "";
|
|
103
|
-
delete item.innerSpacingBefore;
|
|
104
|
-
delete item.innerSpacingAfter;
|
|
105
|
-
var url = item.url;
|
|
106
|
-
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
107
|
-
urlItems.push({
|
|
108
|
-
url: url
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
css.walkDecls(function(decl) {
|
|
116
|
-
var values = Tokenizer.parseValues(decl.value);
|
|
117
|
-
values.nodes.forEach(function(value) {
|
|
118
|
-
value.nodes.forEach(processNode);
|
|
119
|
-
});
|
|
120
|
-
decl.value = Tokenizer.stringifyValues(values);
|
|
121
|
-
});
|
|
122
|
-
css.walkAtRules(function(atrule) {
|
|
123
|
-
if(typeof atrule.params === "string") {
|
|
124
|
-
atrule.params = replaceImportsInString(atrule.params);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
options.importItems = importItems;
|
|
129
|
-
options.urlItems = urlItems;
|
|
130
|
-
options.exports = exports;
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
135
|
-
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
var
|
|
139
|
-
var
|
|
140
|
-
var
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
err.
|
|
217
|
-
|
|
218
|
-
:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
Error.
|
|
244
|
-
this
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
CSSLoaderError.prototype
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
var formatCodeFrame = require("babel-code-frame");
|
|
6
|
+
var Tokenizer = require("css-selector-tokenizer");
|
|
7
|
+
var postcss = require("postcss");
|
|
8
|
+
var loaderUtils = require("loader-utils");
|
|
9
|
+
var assign = require("object-assign");
|
|
10
|
+
var getLocalIdent = require("./getLocalIdent");
|
|
11
|
+
|
|
12
|
+
var localByDefault = require("postcss-modules-local-by-default");
|
|
13
|
+
var extractImports = require("postcss-modules-extract-imports");
|
|
14
|
+
var modulesScope = require("postcss-modules-scope");
|
|
15
|
+
var modulesValues = require("postcss-modules-values");
|
|
16
|
+
var cssnano = require("cssnano");
|
|
17
|
+
|
|
18
|
+
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
19
|
+
return function(css) {
|
|
20
|
+
var imports = {};
|
|
21
|
+
var exports = {};
|
|
22
|
+
var importItems = [];
|
|
23
|
+
var urlItems = [];
|
|
24
|
+
|
|
25
|
+
function replaceImportsInString(str) {
|
|
26
|
+
if(options.import) {
|
|
27
|
+
var tokens = str.split(/(\S+)/);
|
|
28
|
+
tokens = tokens.map(function (token) {
|
|
29
|
+
var importIndex = imports["$" + token];
|
|
30
|
+
if(typeof importIndex === "number") {
|
|
31
|
+
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
32
|
+
}
|
|
33
|
+
return token;
|
|
34
|
+
});
|
|
35
|
+
return tokens.join("");
|
|
36
|
+
}
|
|
37
|
+
return str;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if(options.import) {
|
|
41
|
+
css.walkAtRules("import", function(rule) {
|
|
42
|
+
var values = Tokenizer.parseValues(rule.params);
|
|
43
|
+
var url = values.nodes[0].nodes[0];
|
|
44
|
+
if(url.type === "url") {
|
|
45
|
+
url = url.url;
|
|
46
|
+
} else if(url.type === "string") {
|
|
47
|
+
url = url.value;
|
|
48
|
+
} else throw rule.error("Unexpected format" + rule.params);
|
|
49
|
+
values.nodes[0].nodes.shift();
|
|
50
|
+
var mediaQuery = Tokenizer.stringifyValues(values);
|
|
51
|
+
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
|
|
52
|
+
url = loaderUtils.urlToRequest(url, options.root);
|
|
53
|
+
}
|
|
54
|
+
importItems.push({
|
|
55
|
+
url: url,
|
|
56
|
+
mediaQuery: mediaQuery
|
|
57
|
+
});
|
|
58
|
+
rule.remove();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
css.walkRules(function(rule) {
|
|
63
|
+
if(rule.selector === ":export") {
|
|
64
|
+
rule.walkDecls(function(decl) {
|
|
65
|
+
exports[decl.prop] = decl.value;
|
|
66
|
+
});
|
|
67
|
+
rule.remove();
|
|
68
|
+
} else if(/^:import\(.+\)$/.test(rule.selector)) {
|
|
69
|
+
var match = /^:import\((.+)\)$/.exec(rule.selector);
|
|
70
|
+
var url = loaderUtils.parseString(match[1]);
|
|
71
|
+
rule.walkDecls(function(decl) {
|
|
72
|
+
imports["$" + decl.prop] = importItems.length;
|
|
73
|
+
importItems.push({
|
|
74
|
+
url: url,
|
|
75
|
+
export: decl.value
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
rule.remove();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Object.keys(exports).forEach(function(exportName) {
|
|
83
|
+
exports[exportName] = replaceImportsInString(exports[exportName]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
function processNode(item) {
|
|
87
|
+
switch (item.type) {
|
|
88
|
+
case "value":
|
|
89
|
+
item.nodes.forEach(processNode);
|
|
90
|
+
break;
|
|
91
|
+
case "nested-item":
|
|
92
|
+
item.nodes.forEach(processNode);
|
|
93
|
+
break;
|
|
94
|
+
case "item":
|
|
95
|
+
var importIndex = imports["$" + item.name];
|
|
96
|
+
if (typeof importIndex === "number") {
|
|
97
|
+
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "url":
|
|
101
|
+
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
|
|
102
|
+
item.stringType = "";
|
|
103
|
+
delete item.innerSpacingBefore;
|
|
104
|
+
delete item.innerSpacingAfter;
|
|
105
|
+
var url = item.url;
|
|
106
|
+
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
107
|
+
urlItems.push({
|
|
108
|
+
url: url
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
css.walkDecls(function(decl) {
|
|
116
|
+
var values = Tokenizer.parseValues(decl.value);
|
|
117
|
+
values.nodes.forEach(function(value) {
|
|
118
|
+
value.nodes.forEach(processNode);
|
|
119
|
+
});
|
|
120
|
+
decl.value = Tokenizer.stringifyValues(values);
|
|
121
|
+
});
|
|
122
|
+
css.walkAtRules(function(atrule) {
|
|
123
|
+
if(typeof atrule.params === "string") {
|
|
124
|
+
atrule.params = replaceImportsInString(atrule.params);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
options.importItems = importItems;
|
|
129
|
+
options.urlItems = urlItems;
|
|
130
|
+
options.exports = exports;
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
135
|
+
var query = options.query;
|
|
136
|
+
var root = query.root;
|
|
137
|
+
var context = query.context;
|
|
138
|
+
var localIdentName = query.localIdentName || "[hash:base64]";
|
|
139
|
+
var localIdentRegExp = query.localIdentRegExp;
|
|
140
|
+
var forceMinimize = query.minimize;
|
|
141
|
+
var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
|
|
142
|
+
|
|
143
|
+
var customGetLocalIdent = query.getLocalIdent || getLocalIdent;
|
|
144
|
+
|
|
145
|
+
var parserOptions = {
|
|
146
|
+
root: root,
|
|
147
|
+
mode: options.mode,
|
|
148
|
+
url: query.url !== false,
|
|
149
|
+
import: query.import !== false
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
var pipeline = postcss([
|
|
153
|
+
localByDefault({
|
|
154
|
+
mode: options.mode,
|
|
155
|
+
rewriteUrl: function(global, url) {
|
|
156
|
+
if(parserOptions.url){
|
|
157
|
+
if(!loaderUtils.isUrlRequest(url, root)) {
|
|
158
|
+
return url;
|
|
159
|
+
}
|
|
160
|
+
if(global) {
|
|
161
|
+
return loaderUtils.urlToRequest(url, root);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return url;
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
extractImports(),
|
|
168
|
+
modulesValues,
|
|
169
|
+
modulesScope({
|
|
170
|
+
generateScopedName: function generateScopedName (exportName) {
|
|
171
|
+
return customGetLocalIdent(options.loaderContext, localIdentName, exportName, {
|
|
172
|
+
regExp: localIdentRegExp,
|
|
173
|
+
hashPrefix: query.hashPrefix || "",
|
|
174
|
+
context: context
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}),
|
|
178
|
+
parserPlugin(parserOptions)
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
if(minimize) {
|
|
182
|
+
var minimizeOptions = assign({}, query);
|
|
183
|
+
["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents", "autoprefixer"].forEach(function(name) {
|
|
184
|
+
if(typeof minimizeOptions[name] === "undefined")
|
|
185
|
+
minimizeOptions[name] = false;
|
|
186
|
+
});
|
|
187
|
+
pipeline.use(cssnano(minimizeOptions));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
pipeline.process(inputSource, {
|
|
191
|
+
// we need a prefix to avoid path rewriting of PostCSS
|
|
192
|
+
from: "/css-loader!" + options.from,
|
|
193
|
+
to: options.to,
|
|
194
|
+
map: {
|
|
195
|
+
prev: inputMap,
|
|
196
|
+
sourcesContent: true,
|
|
197
|
+
inline: false,
|
|
198
|
+
annotation: false
|
|
199
|
+
}
|
|
200
|
+
}).then(function(result) {
|
|
201
|
+
callback(null, {
|
|
202
|
+
source: result.css,
|
|
203
|
+
map: result.map && result.map.toJSON(),
|
|
204
|
+
exports: parserOptions.exports,
|
|
205
|
+
importItems: parserOptions.importItems,
|
|
206
|
+
importItemRegExpG: /___CSS_LOADER_IMPORT___([0-9]+)___/g,
|
|
207
|
+
importItemRegExp: /___CSS_LOADER_IMPORT___([0-9]+)___/,
|
|
208
|
+
urlItems: parserOptions.urlItems,
|
|
209
|
+
urlItemRegExpG: /___CSS_LOADER_URL___([0-9]+)___/g,
|
|
210
|
+
urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
|
|
211
|
+
});
|
|
212
|
+
}).catch(function(err) {
|
|
213
|
+
if (err.name === 'CssSyntaxError') {
|
|
214
|
+
var wrappedError = new CSSLoaderError(
|
|
215
|
+
'Syntax Error',
|
|
216
|
+
err.reason,
|
|
217
|
+
err.line != null && err.column != null
|
|
218
|
+
? {line: err.line, column: err.column}
|
|
219
|
+
: null,
|
|
220
|
+
err.input.source
|
|
221
|
+
);
|
|
222
|
+
callback(wrappedError);
|
|
223
|
+
} else {
|
|
224
|
+
callback(err);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
function formatMessage(message, loc, source) {
|
|
230
|
+
var formatted = message;
|
|
231
|
+
if (loc) {
|
|
232
|
+
formatted = formatted
|
|
233
|
+
+ ' (' + loc.line + ':' + loc.column + ')';
|
|
234
|
+
}
|
|
235
|
+
if (loc && source) {
|
|
236
|
+
formatted = formatted
|
|
237
|
+
+ '\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
|
|
238
|
+
}
|
|
239
|
+
return formatted;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function CSSLoaderError(name, message, loc, source, error) {
|
|
243
|
+
Error.call(this);
|
|
244
|
+
Error.captureStackTrace(this, CSSLoaderError);
|
|
245
|
+
this.name = name;
|
|
246
|
+
this.error = error;
|
|
247
|
+
this.message = formatMessage(message, loc, source);
|
|
248
|
+
this.hideStack = true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
CSSLoaderError.prototype = Object.create(Error.prototype);
|
|
252
|
+
CSSLoaderError.prototype.constructor = CSSLoaderError;
|
package/locals.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
module.exports = require("./lib/localsLoader");
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
module.exports = require("./lib/localsLoader");
|