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 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!autoprefixer-loader!...")
228
+ require("style-loader!css-loader?importLoaders=1!postcss-loader!...")
208
229
  // => imported resources are handled this way:
209
- require("css-loader?importLoaders=1!autoprefixer-loader!...")
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?-autoprefixer")` to disable removing of deprecated vendor prefixes.
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");
@@ -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
+ };
@@ -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
+ };
@@ -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
+ };
@@ -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 query = options.query;
137
- var root = query.root;
138
- var context = query.context;
139
- var localIdentName = query.localIdentName || "[hash:base64]";
140
- var localIdentRegExp = query.localIdentRegExp;
141
- var forceMinimize = query.minimize;
142
- var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
143
-
144
- var parserOptions = {
145
- root: root,
146
- mode: options.mode,
147
- url: query.url !== false,
148
- import: query.import !== false
149
- };
150
-
151
- var pipeline = postcss([
152
- localByDefault({
153
- mode: options.mode,
154
- rewriteUrl: function(global, url) {
155
- if(parserOptions.url){
156
- if(!loaderUtils.isUrlRequest(url, root)) {
157
- return url;
158
- }
159
- if(global) {
160
- return loaderUtils.urlToRequest(url, root);
161
- }
162
- }
163
- return url;
164
- }
165
- }),
166
- extractImports(),
167
- modulesValues,
168
- modulesScope({
169
- generateScopedName: function(exportName) {
170
- return getLocalIdent(options.loaderContext, localIdentName, exportName, {
171
- regExp: localIdentRegExp,
172
- hashPrefix: query.hashPrefix || "",
173
- context: context
174
- });
175
- }
176
- }),
177
- parserPlugin(parserOptions)
178
- ]);
179
-
180
- if(minimize) {
181
- var minimizeOptions = assign({}, query);
182
- ["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents", "autoprefixer"].forEach(function(name) {
183
- if(typeof minimizeOptions[name] === "undefined")
184
- minimizeOptions[name] = false;
185
- });
186
- pipeline.use(cssnano(minimizeOptions));
187
- }
188
-
189
- pipeline.process(inputSource, {
190
- // we need a prefix to avoid path rewriting of PostCSS
191
- from: "/css-loader!" + options.from,
192
- to: options.to,
193
- map: {
194
- prev: inputMap,
195
- sourcesContent: true,
196
- inline: false,
197
- annotation: false
198
- }
199
- }).then(function(result) {
200
- callback(null, {
201
- source: result.css,
202
- map: result.map && result.map.toJSON(),
203
- exports: parserOptions.exports,
204
- importItems: parserOptions.importItems,
205
- importItemRegExpG: /___CSS_LOADER_IMPORT___([0-9]+)___/g,
206
- importItemRegExp: /___CSS_LOADER_IMPORT___([0-9]+)___/,
207
- urlItems: parserOptions.urlItems,
208
- urlItemRegExpG: /___CSS_LOADER_URL___([0-9]+)___/g,
209
- urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
210
- });
211
- }).catch(function(err) {
212
- if (err.name === 'CssSyntaxError') {
213
- var wrappedError = new CSSLoaderError(
214
- 'Syntax Error',
215
- err.reason,
216
- err.line != null && err.column != null
217
- ? {line: err.line, column: err.column}
218
- : null,
219
- err.input.source
220
- );
221
- callback(wrappedError);
222
- } else {
223
- callback(err);
224
- }
225
- });
226
- };
227
-
228
- function formatMessage(message, loc, source) {
229
- var formatted = message;
230
- if (loc) {
231
- formatted = formatted
232
- + ' (' + loc.line + ':' + loc.column + ')';
233
- }
234
- if (loc && source) {
235
- formatted = formatted
236
- + '\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
237
- }
238
- return formatted;
239
- }
240
-
241
- function CSSLoaderError(name, message, loc, source, error) {
242
- Error.call(this);
243
- Error.captureStackTrace(this, CSSLoaderError);
244
- this.name = name;
245
- this.error = error;
246
- this.message = formatMessage(message, loc, source);
247
- this.hideStack = true;
248
- }
249
-
250
- CSSLoaderError.prototype = Object.create(Error.prototype);
251
- CSSLoaderError.prototype.constructor = CSSLoaderError;
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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "css loader module for webpack",
6
6
  "engines": {