You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+110-2
Original file line number
Diff line number
Diff line change
@@ -22,8 +22,6 @@ Good loaders for requiring your assets are the [file-loader](https://github.com/
22
22
and the [url-loader](https://github.com/webpack/url-loader) which you should specify
23
23
in your config (see [below](https://github.com/webpack-contrib/css-loader#assets)).
24
24
25
-
> ⚠️ **CSS Module users should continue using `v1.0.0` in the meantime**
26
-
27
25
## Requirements
28
26
29
27
This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.
@@ -271,6 +269,116 @@ module.exports = {
271
269
};
272
270
```
273
271
272
+
### PostCSS
273
+
274
+
To begin, you'll need to install `postcss-loader`:
275
+
276
+
```console
277
+
$ npm install postcss-loader --save-dev
278
+
```
279
+
280
+
Visit [postcss-loader](https://github.com/postcss/postcss-loader) readme for more information.
281
+
282
+
**webpack.config.js**
283
+
284
+
```js
285
+
module.exports= {
286
+
module: {
287
+
rules: [
288
+
{
289
+
test:/\.css$/,
290
+
use: [
291
+
{
292
+
loader:'css-loader',
293
+
},
294
+
{
295
+
loader:'postcss-loader',
296
+
},
297
+
],
298
+
},
299
+
],
300
+
},
301
+
};
302
+
```
303
+
304
+
### CSS Modules
305
+
306
+
To begin, you'll need to install `postcss-loader`, `postcss-icss-values`, `postcss-icss-selectors`, `postcss-icss-composes` and `postcss-icss-keyframes`:
New `postcss` plugins for css modules use the [ICSS](https://github.com/css-modules/icss) specification.
313
+
314
+
**webpack.config.js**
315
+
316
+
```js
317
+
module.exports= {
318
+
module: {
319
+
rules: [
320
+
{
321
+
test:/\.modules.css$/,
322
+
use: [
323
+
{
324
+
loader:'css-loader',
325
+
options: {
326
+
importLoaders:1,
327
+
},
328
+
},
329
+
{
330
+
loader:'postcss-loader',
331
+
options: {
332
+
plugins: (loader) => [
333
+
require('postcss-icss-values')(),
334
+
require('postcss-icss-selectors')({
335
+
mode:'global', // Can be `local`
336
+
generateScopedName:require('generic-names')({
337
+
hashPrefix:'',
338
+
context:loader.rootContext,
339
+
})
340
+
}),
341
+
require('postcss-icss-composes')(),
342
+
require('postcss-icss-keyframes')({
343
+
generateScopedName:require('generic-names')({
344
+
hashPrefix:'',
345
+
context:loader.rootContext,
346
+
})
347
+
}),
348
+
],
349
+
},
350
+
},
351
+
],
352
+
},
353
+
],
354
+
},
355
+
};
356
+
```
357
+
358
+
### Custom Export
359
+
360
+
Due to the [ICSS](https://github.com/css-modules/icss) specification, you can export any values from your styles.
361
+
362
+
Just add `:export {}` with exported values. You can use `postcss-loader` with own `postcss` plugin to automate these actions. [Writing a PostCSS Plugin](Writing a PostCSS Plugin).
363
+
364
+
Example:
365
+
366
+
**style.css**
367
+
368
+
```css
369
+
:export {
370
+
color: black;
371
+
}
372
+
```
373
+
374
+
**file.js**
375
+
376
+
```js
377
+
importstylesfrom'style.css'
378
+
379
+
console.log(styles.color); // Output `black`
380
+
```
381
+
274
382
## Contributing
275
383
276
384
Please take a moment to read our contributing guidelines if you haven't yet done so.
0 commit comments