css-loader 2.1.1 → 3.0.0
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/CHANGELOG.md +34 -1
- package/README.md +252 -98
- package/dist/index.js +39 -178
- package/dist/options.json +43 -36
- package/dist/plugins/postcss-icss-parser.js +48 -62
- package/dist/plugins/postcss-import-parser.js +4 -6
- package/dist/plugins/postcss-url-parser.js +60 -40
- package/dist/runtime/api.js +15 -10
- package/dist/runtime/{url-escape.js → getUrl.js} +3 -2
- package/dist/utils.js +263 -30
- package/package.json +48 -79
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [3.0.0](https://github.com/webpack-contrib/css-loader/compare/v2.1.1...v3.0.0) (2019-06-11)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* avoid the "from" argument must be of type string error ([#908](https://github.com/webpack-contrib/css-loader/issues/908)) ([e5dfd23](https://github.com/webpack-contrib/css-loader/commit/e5dfd23))
|
|
11
|
+
* invert `Function` behavior for `url` and `import` options ([#939](https://github.com/webpack-contrib/css-loader/issues/939)) ([e9eb5ad](https://github.com/webpack-contrib/css-loader/commit/e9eb5ad))
|
|
12
|
+
* properly export locals with escaped characters ([#917](https://github.com/webpack-contrib/css-loader/issues/917)) ([a0efcda](https://github.com/webpack-contrib/css-loader/commit/a0efcda))
|
|
13
|
+
* property handle non css characters in localIdentName ([#920](https://github.com/webpack-contrib/css-loader/issues/920)) ([d3a0a3c](https://github.com/webpack-contrib/css-loader/commit/d3a0a3c))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* modules options now accepts object config ([#937](https://github.com/webpack-contrib/css-loader/issues/937)) ([1d7a464](https://github.com/webpack-contrib/css-loader/commit/1d7a464))
|
|
19
|
+
* support `@value` at-rule in selectors ([#941](https://github.com/webpack-contrib/css-loader/issues/941)) ([05a42e2](https://github.com/webpack-contrib/css-loader/commit/05a42e2))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* minimum required nodejs version is 8.9.0
|
|
25
|
+
* `@value` at rules now support in `selector`, recommends checking all `@values` at-rule usage (hint: you can add prefix to all `@value` at-rules, for example `@value v-foo: black;` or `@value m-foo: screen and (max-width: 12450px)`, and then do upgrade)
|
|
26
|
+
* invert `{Function}` behavior for `url` and `import` options (need return `true` when you want handle `url`/`@import` and return `false` if not)
|
|
27
|
+
* `exportLocalsStyle` option was remove in favor `localsConvention` option, also it is accept only `{String}` value (use `camelCase` value if you previously value was `true` and `asIs` if you previously value was `false`)
|
|
28
|
+
* `exportOnlyLocals` option was remove in favor `onlyLocals` option
|
|
29
|
+
* `modules` option now can be `{Object}` and allow to setup `CSS Modules` options:
|
|
30
|
+
* `localIdentName` option was removed in favor `modules.localIdentName` option
|
|
31
|
+
* `context` option was remove in favor `modules.context` option
|
|
32
|
+
* `hashPrefix` option was removed in favor `modules.hashPrefix` option
|
|
33
|
+
* `getLocalIdent` option was removed in favor `modules.getLocalIdent` option
|
|
34
|
+
* `localIdentRegExp` option was removed in favor `modules.localIdentRegExp` option
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
5
38
|
<a name="2.1.1"></a>
|
|
6
39
|
## [2.1.1](https://github.com/webpack-contrib/css-loader/compare/v2.1.0...v2.1.1) (2019-03-07)
|
|
7
40
|
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ module.exports = {
|
|
|
42
42
|
module: {
|
|
43
43
|
rules: [
|
|
44
44
|
{
|
|
45
|
-
test: /\.css
|
|
45
|
+
test: /\.css$/i,
|
|
46
46
|
use: ['style-loader', 'css-loader'],
|
|
47
47
|
},
|
|
48
48
|
],
|
|
@@ -65,7 +65,7 @@ module.exports = {
|
|
|
65
65
|
module: {
|
|
66
66
|
rules: [
|
|
67
67
|
{
|
|
68
|
-
test: /\.css
|
|
68
|
+
test: /\.css$/i,
|
|
69
69
|
use: ['to-string-loader', 'css-loader'],
|
|
70
70
|
},
|
|
71
71
|
],
|
|
@@ -95,7 +95,7 @@ module.exports = {
|
|
|
95
95
|
module: {
|
|
96
96
|
rules: [
|
|
97
97
|
{
|
|
98
|
-
test: /\.css
|
|
98
|
+
test: /\.css$/i,
|
|
99
99
|
use: [
|
|
100
100
|
'handlebars-loader', // handlebars loader expects raw resource string
|
|
101
101
|
'extract-loader',
|
|
@@ -109,19 +109,15 @@ module.exports = {
|
|
|
109
109
|
|
|
110
110
|
## Options
|
|
111
111
|
|
|
112
|
-
| Name |
|
|
113
|
-
| :-----------------------------------------: |
|
|
114
|
-
| **[`url`](#url)** |
|
|
115
|
-
| **[`import`](#import)** |
|
|
116
|
-
| **[`modules`](#modules)** |
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
121
|
-
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enable/Disable Sourcemaps |
|
|
122
|
-
| **[`camelCase`](#camelcase)** | `{Boolean\|String}` | `false` | Export Classnames in CamelCase |
|
|
123
|
-
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Number of loaders applied before CSS loader |
|
|
124
|
-
| **[`exportOnlyLocals`](#exportonlylocals)** | `{Boolean}` | `false` | Export only locals |
|
|
112
|
+
| Name | Type | Default | Description |
|
|
113
|
+
| :-----------------------------------------: | :-------------------------: | :-----: | :------------------------------------------------- |
|
|
114
|
+
| **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enable/Disable `url()` handling |
|
|
115
|
+
| **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enable/Disable @import handling |
|
|
116
|
+
| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `false` | Enable/Disable CSS Modules and setup their options |
|
|
117
|
+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `false` | Enable/Disable Sourcemaps |
|
|
118
|
+
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Number of loaders applied before CSS loader |
|
|
119
|
+
| **[`localsConvention`](#localsconvention)** | `{String}` | `asIs` | Setup style of exported classnames |
|
|
120
|
+
| **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
|
|
125
121
|
|
|
126
122
|
### `url`
|
|
127
123
|
|
|
@@ -160,7 +156,7 @@ module.exports = {
|
|
|
160
156
|
module: {
|
|
161
157
|
rules: [
|
|
162
158
|
{
|
|
163
|
-
test: /\.css
|
|
159
|
+
test: /\.css$/i,
|
|
164
160
|
loader: 'css-loader',
|
|
165
161
|
options: {
|
|
166
162
|
url: true,
|
|
@@ -182,14 +178,18 @@ module.exports = {
|
|
|
182
178
|
module: {
|
|
183
179
|
rules: [
|
|
184
180
|
{
|
|
185
|
-
test: /\.css
|
|
181
|
+
test: /\.css$/i,
|
|
186
182
|
loader: 'css-loader',
|
|
187
183
|
options: {
|
|
188
184
|
url: (url, resourcePath) => {
|
|
189
185
|
// resourcePath - path to css file
|
|
190
186
|
|
|
191
|
-
//
|
|
192
|
-
|
|
187
|
+
// Don't handle `img.png` urls
|
|
188
|
+
if (url.includes('img.png')) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return true;
|
|
193
193
|
},
|
|
194
194
|
},
|
|
195
195
|
},
|
|
@@ -236,7 +236,7 @@ module.exports = {
|
|
|
236
236
|
module: {
|
|
237
237
|
rules: [
|
|
238
238
|
{
|
|
239
|
-
test: /\.css
|
|
239
|
+
test: /\.css$/i,
|
|
240
240
|
loader: 'css-loader',
|
|
241
241
|
options: {
|
|
242
242
|
import: true,
|
|
@@ -258,7 +258,7 @@ module.exports = {
|
|
|
258
258
|
module: {
|
|
259
259
|
rules: [
|
|
260
260
|
{
|
|
261
|
-
test: /\.css
|
|
261
|
+
test: /\.css$/i,
|
|
262
262
|
loader: 'css-loader',
|
|
263
263
|
options: {
|
|
264
264
|
import: (parsedImport, resourcePath) => {
|
|
@@ -266,8 +266,12 @@ module.exports = {
|
|
|
266
266
|
// parsedImport.media - media query of `@import`
|
|
267
267
|
// resourcePath - path to css file
|
|
268
268
|
|
|
269
|
-
//
|
|
270
|
-
|
|
269
|
+
// Don't handle `style.css` import
|
|
270
|
+
if (parsedImport.url.includes('style.css')) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return true;
|
|
271
275
|
},
|
|
272
276
|
},
|
|
273
277
|
},
|
|
@@ -276,24 +280,15 @@ module.exports = {
|
|
|
276
280
|
};
|
|
277
281
|
```
|
|
278
282
|
|
|
279
|
-
###
|
|
283
|
+
### `modules`
|
|
280
284
|
|
|
281
|
-
Type: `Boolean|String`
|
|
285
|
+
Type: `Boolean|String|Object`
|
|
282
286
|
Default: `false`
|
|
283
287
|
|
|
284
|
-
The `modules` option enables/disables the **CSS Modules**
|
|
285
|
-
|
|
286
|
-
| Name | Type | Description |
|
|
287
|
-
| :------------: | :---------: | :------------------------------------------------------------------------------------------------------------------------------- |
|
|
288
|
-
| **`true`** | `{Boolean}` | Enables local scoped CSS by default (use **local** mode by default) |
|
|
289
|
-
| **`false`** | `{Boolean}` | Disable the **CSS Modules** spec, all **CSS Modules** features (like `@value`, `:local`, `:global` and `composes`) will not work |
|
|
290
|
-
| **`'local'`** | `{String}` | Enables local scoped CSS by default (same as `true` value) |
|
|
291
|
-
| **`'global'`** | `{String}` | Enables global scoped CSS by default |
|
|
288
|
+
The `modules` option enables/disables the **[CSS Modules](https://github.com/css-modules/css-modules)** specification and setup basic behaviour.
|
|
292
289
|
|
|
293
290
|
Using `false` value increase performance because we avoid parsing **CSS Modules** features, it will be useful for developers who use vanilla css or use other technologies.
|
|
294
291
|
|
|
295
|
-
You can read about **modes** below.
|
|
296
|
-
|
|
297
292
|
**webpack.config.js**
|
|
298
293
|
|
|
299
294
|
```js
|
|
@@ -301,7 +296,7 @@ module.exports = {
|
|
|
301
296
|
module: {
|
|
302
297
|
rules: [
|
|
303
298
|
{
|
|
304
|
-
test: /\.css
|
|
299
|
+
test: /\.css$/i,
|
|
305
300
|
loader: 'css-loader',
|
|
306
301
|
options: {
|
|
307
302
|
modules: true,
|
|
@@ -312,6 +307,8 @@ module.exports = {
|
|
|
312
307
|
};
|
|
313
308
|
```
|
|
314
309
|
|
|
310
|
+
#### `Features`
|
|
311
|
+
|
|
315
312
|
##### `Scope`
|
|
316
313
|
|
|
317
314
|
Using `local` value requires you to specify `:global` classes.
|
|
@@ -324,7 +321,7 @@ Styles can be locally scoped to avoid globally scoping styles.
|
|
|
324
321
|
The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.
|
|
325
322
|
|
|
326
323
|
With `:local` (without brackets) local mode can be switched on for this selector.
|
|
327
|
-
The `:global(.className)`
|
|
324
|
+
The `:global(.className)` notation can be used to declare an explicit global selector.
|
|
328
325
|
With `:global` (without brackets) global mode can be switched on for this selector.
|
|
329
326
|
|
|
330
327
|
The loader replaces local selectors with unique identifiers. The chosen unique identifiers are exported by the module.
|
|
@@ -437,7 +434,133 @@ To import from multiple modules use multiple `composes:` rules.
|
|
|
437
434
|
}
|
|
438
435
|
```
|
|
439
436
|
|
|
440
|
-
|
|
437
|
+
##### `Values`
|
|
438
|
+
|
|
439
|
+
You can use `@value` to specific values to be reused throughout a document.
|
|
440
|
+
|
|
441
|
+
We recommend use prefix `v-` for values, `s-` for selectors and `m-` for media at-rules.
|
|
442
|
+
|
|
443
|
+
```css
|
|
444
|
+
@value v-primary: #BF4040;
|
|
445
|
+
@value s-black: black-selector;
|
|
446
|
+
@value m-large: (min-width: 960px);
|
|
447
|
+
|
|
448
|
+
.header {
|
|
449
|
+
color: v-primary;
|
|
450
|
+
padding: 0 10px;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
.s-black {
|
|
454
|
+
color: black;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
@media m-large {
|
|
458
|
+
.header {
|
|
459
|
+
padding: 0 20px;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
#### `Boolean`
|
|
465
|
+
|
|
466
|
+
Enable **CSS Modules** features.
|
|
467
|
+
|
|
468
|
+
**webpack.config.js**
|
|
469
|
+
|
|
470
|
+
```js
|
|
471
|
+
module.exports = {
|
|
472
|
+
module: {
|
|
473
|
+
rules: [
|
|
474
|
+
{
|
|
475
|
+
test: /\.css$/i,
|
|
476
|
+
loader: 'css-loader',
|
|
477
|
+
options: {
|
|
478
|
+
modules: true,
|
|
479
|
+
},
|
|
480
|
+
},
|
|
481
|
+
],
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
#### `String`
|
|
487
|
+
|
|
488
|
+
Enable **CSS Modules** features and setup `mode`.
|
|
489
|
+
|
|
490
|
+
**webpack.config.js**
|
|
491
|
+
|
|
492
|
+
```js
|
|
493
|
+
module.exports = {
|
|
494
|
+
module: {
|
|
495
|
+
rules: [
|
|
496
|
+
{
|
|
497
|
+
test: /\.css$/i,
|
|
498
|
+
loader: 'css-loader',
|
|
499
|
+
options: {
|
|
500
|
+
// Using `local` value has same effect like using `modules: true`
|
|
501
|
+
modules: 'global',
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
],
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### `Object`
|
|
510
|
+
|
|
511
|
+
Enable **CSS Modules** features and setup options for them.
|
|
512
|
+
|
|
513
|
+
**webpack.config.js**
|
|
514
|
+
|
|
515
|
+
```js
|
|
516
|
+
module.exports = {
|
|
517
|
+
module: {
|
|
518
|
+
rules: [
|
|
519
|
+
{
|
|
520
|
+
test: /\.css$/i,
|
|
521
|
+
loader: 'css-loader',
|
|
522
|
+
options: {
|
|
523
|
+
modules: {
|
|
524
|
+
mode: 'local',
|
|
525
|
+
localIdentName: '[path][name]__[local]--[hash:base64:5]',
|
|
526
|
+
context: path.resolve(__dirname, 'src'),
|
|
527
|
+
hashPrefix: 'my-custom-hash',
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
},
|
|
533
|
+
};
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
##### `mode`
|
|
537
|
+
|
|
538
|
+
Type: `String`
|
|
539
|
+
Default: `local`
|
|
540
|
+
|
|
541
|
+
Setup `mode` option. You can omit the value when you want `local` mode.
|
|
542
|
+
|
|
543
|
+
**webpack.config.js**
|
|
544
|
+
|
|
545
|
+
```js
|
|
546
|
+
module.exports = {
|
|
547
|
+
module: {
|
|
548
|
+
rules: [
|
|
549
|
+
{
|
|
550
|
+
test: /\.css$/i,
|
|
551
|
+
loader: 'css-loader',
|
|
552
|
+
options: {
|
|
553
|
+
modules: {
|
|
554
|
+
mode: 'global',
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
],
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
##### `localIdentName`
|
|
441
564
|
|
|
442
565
|
Type: `String`
|
|
443
566
|
Default: `[hash:base64]`
|
|
@@ -452,11 +575,12 @@ module.exports = {
|
|
|
452
575
|
module: {
|
|
453
576
|
rules: [
|
|
454
577
|
{
|
|
455
|
-
test: /\.css
|
|
578
|
+
test: /\.css$/i,
|
|
456
579
|
loader: 'css-loader',
|
|
457
580
|
options: {
|
|
458
|
-
modules:
|
|
459
|
-
|
|
581
|
+
modules: {
|
|
582
|
+
localIdentName: '[path][name]__[local]--[hash:base64:5]',
|
|
583
|
+
},
|
|
460
584
|
},
|
|
461
585
|
},
|
|
462
586
|
],
|
|
@@ -464,7 +588,7 @@ module.exports = {
|
|
|
464
588
|
};
|
|
465
589
|
```
|
|
466
590
|
|
|
467
|
-
|
|
591
|
+
##### `context`
|
|
468
592
|
|
|
469
593
|
Type: `String`
|
|
470
594
|
Default: `undefined`
|
|
@@ -479,11 +603,12 @@ module.exports = {
|
|
|
479
603
|
module: {
|
|
480
604
|
rules: [
|
|
481
605
|
{
|
|
482
|
-
test: /\.css
|
|
606
|
+
test: /\.css$/i,
|
|
483
607
|
loader: 'css-loader',
|
|
484
608
|
options: {
|
|
485
|
-
modules:
|
|
486
|
-
|
|
609
|
+
modules: {
|
|
610
|
+
context: path.resolve(__dirname, 'context'),
|
|
611
|
+
},
|
|
487
612
|
},
|
|
488
613
|
},
|
|
489
614
|
],
|
|
@@ -491,7 +616,7 @@ module.exports = {
|
|
|
491
616
|
};
|
|
492
617
|
```
|
|
493
618
|
|
|
494
|
-
|
|
619
|
+
##### `hashPrefix`
|
|
495
620
|
|
|
496
621
|
Type: `String`
|
|
497
622
|
Default: `undefined`
|
|
@@ -505,11 +630,12 @@ module.exports = {
|
|
|
505
630
|
module: {
|
|
506
631
|
rules: [
|
|
507
632
|
{
|
|
508
|
-
test: /\.css
|
|
633
|
+
test: /\.css$/i,
|
|
509
634
|
loader: 'css-loader',
|
|
510
635
|
options: {
|
|
511
|
-
modules:
|
|
512
|
-
|
|
636
|
+
modules: {
|
|
637
|
+
hashPrefix: 'hash',
|
|
638
|
+
},
|
|
513
639
|
},
|
|
514
640
|
},
|
|
515
641
|
],
|
|
@@ -517,7 +643,7 @@ module.exports = {
|
|
|
517
643
|
};
|
|
518
644
|
```
|
|
519
645
|
|
|
520
|
-
|
|
646
|
+
##### `getLocalIdent`
|
|
521
647
|
|
|
522
648
|
Type: `Function`
|
|
523
649
|
Default: `undefined`
|
|
@@ -532,12 +658,13 @@ module.exports = {
|
|
|
532
658
|
module: {
|
|
533
659
|
rules: [
|
|
534
660
|
{
|
|
535
|
-
test: /\.css
|
|
661
|
+
test: /\.css$/i,
|
|
536
662
|
loader: 'css-loader',
|
|
537
663
|
options: {
|
|
538
|
-
modules:
|
|
539
|
-
|
|
540
|
-
|
|
664
|
+
modules: {
|
|
665
|
+
getLocalIdent: (context, localIdentName, localName, options) => {
|
|
666
|
+
return 'whatever_random_class_name';
|
|
667
|
+
},
|
|
541
668
|
},
|
|
542
669
|
},
|
|
543
670
|
},
|
|
@@ -546,16 +673,10 @@ module.exports = {
|
|
|
546
673
|
};
|
|
547
674
|
```
|
|
548
675
|
|
|
549
|
-
|
|
676
|
+
##### `localIdentRegExp`
|
|
550
677
|
|
|
551
|
-
Type: `
|
|
552
|
-
Default: `
|
|
553
|
-
|
|
554
|
-
To include source maps set the `sourceMap` option.
|
|
555
|
-
|
|
556
|
-
I.e. the `mini-css-extract-plugin` can handle them.
|
|
557
|
-
|
|
558
|
-
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not). In addition to that relative paths are buggy and you need to use an absolute public path which includes the server URL.
|
|
678
|
+
Type: `String|RegExp`
|
|
679
|
+
Default: `undefined`
|
|
559
680
|
|
|
560
681
|
**webpack.config.js**
|
|
561
682
|
|
|
@@ -564,10 +685,12 @@ module.exports = {
|
|
|
564
685
|
module: {
|
|
565
686
|
rules: [
|
|
566
687
|
{
|
|
567
|
-
test: /\.css
|
|
688
|
+
test: /\.css$/i,
|
|
568
689
|
loader: 'css-loader',
|
|
569
690
|
options: {
|
|
570
|
-
|
|
691
|
+
modules: {
|
|
692
|
+
localIdentRegExp: /page-(.*)\.css/i,
|
|
693
|
+
},
|
|
571
694
|
},
|
|
572
695
|
},
|
|
573
696
|
],
|
|
@@ -575,33 +698,18 @@ module.exports = {
|
|
|
575
698
|
};
|
|
576
699
|
```
|
|
577
700
|
|
|
578
|
-
### `
|
|
701
|
+
### `sourceMap`
|
|
579
702
|
|
|
580
|
-
Type: `Boolean
|
|
703
|
+
Type: `Boolean`
|
|
581
704
|
Default: `false`
|
|
582
705
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
| Name | Type | Description |
|
|
586
|
-
| :----------------: | :---------: | :----------------------------------------------------------------------------------------------------------------------- |
|
|
587
|
-
| **`false`** | `{Boolean}` | Class names will be camelized, the original class name will not to be removed from the locals |
|
|
588
|
-
| **`true`** | `{Boolean}` | Class names will be camelized |
|
|
589
|
-
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
|
|
590
|
-
| **`'only'`** | `{String}` | Introduced in `0.27.1`. Class names will be camelized, the original class name will be removed from the locals |
|
|
591
|
-
| **`'dashesOnly'`** | `{String}` | Introduced in `0.27.1`. Dashes in class names will be camelized, the original class name will be removed from the locals |
|
|
592
|
-
|
|
593
|
-
**file.css**
|
|
706
|
+
To include source maps set the `sourceMap` option.
|
|
594
707
|
|
|
595
|
-
|
|
596
|
-
.class-name {
|
|
597
|
-
}
|
|
598
|
-
```
|
|
708
|
+
I.e. the `mini-css-extract-plugin` can handle them.
|
|
599
709
|
|
|
600
|
-
|
|
710
|
+
They are not enabled by default because they expose a runtime overhead and increase in bundle size (JS source maps do not).
|
|
601
711
|
|
|
602
|
-
|
|
603
|
-
import { className } from 'file.css';
|
|
604
|
-
```
|
|
712
|
+
In addition to that relative paths are buggy and you need to use an absolute public path which includes the server URL.
|
|
605
713
|
|
|
606
714
|
**webpack.config.js**
|
|
607
715
|
|
|
@@ -610,10 +718,10 @@ module.exports = {
|
|
|
610
718
|
module: {
|
|
611
719
|
rules: [
|
|
612
720
|
{
|
|
613
|
-
test: /\.css
|
|
721
|
+
test: /\.css$/i,
|
|
614
722
|
loader: 'css-loader',
|
|
615
723
|
options: {
|
|
616
|
-
|
|
724
|
+
sourceMap: true,
|
|
617
725
|
},
|
|
618
726
|
},
|
|
619
727
|
],
|
|
@@ -635,7 +743,7 @@ module.exports = {
|
|
|
635
743
|
module: {
|
|
636
744
|
rules: [
|
|
637
745
|
{
|
|
638
|
-
test: /\.css
|
|
746
|
+
test: /\.css$/i,
|
|
639
747
|
use: [
|
|
640
748
|
'style-loader',
|
|
641
749
|
{
|
|
@@ -655,7 +763,53 @@ module.exports = {
|
|
|
655
763
|
|
|
656
764
|
This may change in the future when the module system (i. e. webpack) supports loader matching by origin.
|
|
657
765
|
|
|
658
|
-
### `
|
|
766
|
+
### `localsConvention`
|
|
767
|
+
|
|
768
|
+
Type: `String`
|
|
769
|
+
Default: `undefined`
|
|
770
|
+
|
|
771
|
+
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
772
|
+
|
|
773
|
+
| Name | Type | Description |
|
|
774
|
+
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
|
|
775
|
+
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
|
|
776
|
+
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
|
|
777
|
+
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
|
|
778
|
+
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
|
|
779
|
+
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
|
|
780
|
+
|
|
781
|
+
**file.css**
|
|
782
|
+
|
|
783
|
+
```css
|
|
784
|
+
.class-name {
|
|
785
|
+
}
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
**file.js**
|
|
789
|
+
|
|
790
|
+
```js
|
|
791
|
+
import { className } from 'file.css';
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
**webpack.config.js**
|
|
795
|
+
|
|
796
|
+
```js
|
|
797
|
+
module.exports = {
|
|
798
|
+
module: {
|
|
799
|
+
rules: [
|
|
800
|
+
{
|
|
801
|
+
test: /\.css$/i,
|
|
802
|
+
loader: 'css-loader',
|
|
803
|
+
options: {
|
|
804
|
+
localsConvention: 'camelCase',
|
|
805
|
+
},
|
|
806
|
+
},
|
|
807
|
+
],
|
|
808
|
+
},
|
|
809
|
+
};
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
### `onlyLocals`
|
|
659
813
|
|
|
660
814
|
Type: `Boolean`
|
|
661
815
|
Default: `false`
|
|
@@ -671,10 +825,10 @@ module.exports = {
|
|
|
671
825
|
module: {
|
|
672
826
|
rules: [
|
|
673
827
|
{
|
|
674
|
-
test: /\.css
|
|
828
|
+
test: /\.css$/i,
|
|
675
829
|
loader: 'css-loader',
|
|
676
830
|
options: {
|
|
677
|
-
|
|
831
|
+
onlyLocals: true,
|
|
678
832
|
},
|
|
679
833
|
},
|
|
680
834
|
],
|
|
@@ -695,14 +849,14 @@ module.exports = {
|
|
|
695
849
|
module: {
|
|
696
850
|
rules: [
|
|
697
851
|
{
|
|
698
|
-
test: /\.css
|
|
852
|
+
test: /\.css$/i,
|
|
699
853
|
use: ['style-loader', 'css-loader'],
|
|
700
854
|
},
|
|
701
855
|
{
|
|
702
|
-
test: /\.(png|
|
|
856
|
+
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
|
|
703
857
|
loader: 'url-loader',
|
|
704
858
|
options: {
|
|
705
|
-
limit:
|
|
859
|
+
limit: 8192,
|
|
706
860
|
},
|
|
707
861
|
},
|
|
708
862
|
],
|
|
@@ -734,8 +888,8 @@ Please take a moment to read our contributing guidelines if you haven't yet done
|
|
|
734
888
|
[node-url]: https://nodejs.org
|
|
735
889
|
[deps]: https://david-dm.org/webpack-contrib/css-loader.svg
|
|
736
890
|
[deps-url]: https://david-dm.org/webpack-contrib/css-loader
|
|
737
|
-
[tests]: https://
|
|
738
|
-
[tests-url]: https://
|
|
891
|
+
[tests]: https://dev.azure.com/webpack-contrib/css-loader/_apis/build/status/webpack-contrib.css-loader?branchName=master
|
|
892
|
+
[tests-url]: https://dev.azure.com/webpack-contrib/css-loader/_build/latest?definitionId=2&branchName=master
|
|
739
893
|
[cover]: https://codecov.io/gh/webpack-contrib/css-loader/branch/master/graph/badge.svg
|
|
740
894
|
[cover-url]: https://codecov.io/gh/webpack-contrib/css-loader
|
|
741
895
|
[chat]: https://badges.gitter.im/webpack/webpack.svg
|