css-loader 0.23.1 → 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/.github/ISSUE_TEMPLATE.md +15 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +18 -0
- package/README.md +47 -5
- package/lib/getLocalIdent.js +1 -1
- package/lib/processCss.js +44 -5
- package/package.json +10 -6
|
@@ -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/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
|
|
10
10
|
|
|
11
11
|
``` javascript
|
|
12
|
-
var css = require("css!./file.css");
|
|
12
|
+
var css = require("css-loader!./file.css");
|
|
13
13
|
// => returns css code from file.css, resolves imports and url(...)
|
|
14
14
|
```
|
|
15
15
|
|
|
@@ -62,7 +62,7 @@ Using 'Root-relative' urls is not recommended. You should only use it for legacy
|
|
|
62
62
|
|
|
63
63
|
### Local scope
|
|
64
64
|
|
|
65
|
-
By default CSS exports all class names into a global selector scope.
|
|
65
|
+
By default CSS exports all class names into a global selector scope. Styles can be locally scoped to avoid globally scoping styles.
|
|
66
66
|
|
|
67
67
|
The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.
|
|
68
68
|
|
|
@@ -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
|
|
|
@@ -233,6 +254,27 @@ You can also disable or enforce minification with the `minimize` query parameter
|
|
|
233
254
|
|
|
234
255
|
`css-loader?-import` disables `@import` handling.
|
|
235
256
|
|
|
257
|
+
### Camel case
|
|
258
|
+
|
|
259
|
+
By default, the exported JSON keys mirror the class names. If you want to camelize class names (useful in Javascript), pass the query parameter `camelCase` to the loader.
|
|
260
|
+
|
|
261
|
+
Example:
|
|
262
|
+
|
|
263
|
+
`css-loader?camelCase`
|
|
264
|
+
|
|
265
|
+
Usage:
|
|
266
|
+
```css
|
|
267
|
+
/* file.css */
|
|
268
|
+
|
|
269
|
+
.class-name { /* ... */ }
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
```js
|
|
273
|
+
// javascript
|
|
274
|
+
|
|
275
|
+
require('file.css').className
|
|
276
|
+
```
|
|
277
|
+
|
|
236
278
|
## License
|
|
237
279
|
|
|
238
280
|
MIT (http://www.opensource.org/licenses/mit-license.php)
|
package/lib/getLocalIdent.js
CHANGED
|
@@ -12,5 +12,5 @@ module.exports = function getLocalIdent(loaderContext, localIdentName, localName
|
|
|
12
12
|
options.content = options.hashPrefix + request + "+" + localName;
|
|
13
13
|
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
|
|
14
14
|
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
|
|
15
|
-
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^([
|
|
15
|
+
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
|
|
16
16
|
};
|
package/lib/processCss.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
|
+
var formatCodeFrame = require("babel-code-frame");
|
|
5
6
|
var Tokenizer = require("css-selector-tokenizer");
|
|
6
7
|
var postcss = require("postcss");
|
|
7
8
|
var loaderUtils = require("loader-utils");
|
|
@@ -131,7 +132,6 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
|
131
132
|
});
|
|
132
133
|
|
|
133
134
|
module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
134
|
-
|
|
135
135
|
var query = options.query;
|
|
136
136
|
var root = query.root;
|
|
137
137
|
var context = query.context;
|
|
@@ -140,6 +140,8 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
140
140
|
var forceMinimize = query.minimize;
|
|
141
141
|
var minimize = typeof forceMinimize !== "undefined" ? !!forceMinimize : options.minimize;
|
|
142
142
|
|
|
143
|
+
var customGetLocalIdent = query.getLocalIdent || getLocalIdent;
|
|
144
|
+
|
|
143
145
|
var parserOptions = {
|
|
144
146
|
root: root,
|
|
145
147
|
mode: options.mode,
|
|
@@ -165,8 +167,8 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
165
167
|
extractImports(),
|
|
166
168
|
modulesValues,
|
|
167
169
|
modulesScope({
|
|
168
|
-
generateScopedName: function(exportName) {
|
|
169
|
-
return
|
|
170
|
+
generateScopedName: function generateScopedName (exportName) {
|
|
171
|
+
return customGetLocalIdent(options.loaderContext, localIdentName, exportName, {
|
|
170
172
|
regExp: localIdentRegExp,
|
|
171
173
|
hashPrefix: query.hashPrefix || "",
|
|
172
174
|
context: context
|
|
@@ -178,7 +180,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
178
180
|
|
|
179
181
|
if(minimize) {
|
|
180
182
|
var minimizeOptions = assign({}, query);
|
|
181
|
-
["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents"].forEach(function(name) {
|
|
183
|
+
["zindex", "normalizeUrl", "discardUnused", "mergeIdents", "reduceIdents", "autoprefixer"].forEach(function(name) {
|
|
182
184
|
if(typeof minimizeOptions[name] === "undefined")
|
|
183
185
|
minimizeOptions[name] = false;
|
|
184
186
|
});
|
|
@@ -208,6 +210,43 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
208
210
|
urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
|
|
209
211
|
});
|
|
210
212
|
}).catch(function(err) {
|
|
211
|
-
|
|
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
|
+
}
|
|
212
226
|
});
|
|
213
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/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"author": "Tobias Koppers @sokra",
|
|
5
5
|
"description": "css loader module for webpack",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=0.12.0"
|
|
8
|
+
},
|
|
6
9
|
"dependencies": {
|
|
7
|
-
"
|
|
10
|
+
"babel-code-frame": "^6.11.0",
|
|
11
|
+
"css-selector-tokenizer": "^0.7.0",
|
|
8
12
|
"cssnano": ">=2.6.1 <4",
|
|
9
13
|
"loader-utils": "~0.2.2",
|
|
14
|
+
"lodash.camelcase": "^4.3.0",
|
|
10
15
|
"object-assign": "^4.0.1",
|
|
11
|
-
"lodash.camelcase": "^3.0.1",
|
|
12
16
|
"postcss": "^5.0.6",
|
|
13
17
|
"postcss-modules-extract-imports": "^1.0.0",
|
|
14
18
|
"postcss-modules-local-by-default": "^1.0.1",
|
|
@@ -19,9 +23,9 @@
|
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"codecov.io": "^0.1.2",
|
|
21
25
|
"coveralls": "^2.11.2",
|
|
22
|
-
"istanbul": "^0.
|
|
23
|
-
"mocha": "^
|
|
24
|
-
"should": "^
|
|
26
|
+
"istanbul": "^0.4.5",
|
|
27
|
+
"mocha": "^3.1.2",
|
|
28
|
+
"should": "^11.1.1"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|
|
27
31
|
"test": "mocha",
|