1 | # webpack-handle-css-loader
|
2 |
|
3 | [![NPM version](https://img.shields.io/npm/v/webpack-handle-css-loader.svg?style=flat-square)](https://npmjs.com/package/webpack-handle-css-loader) [![NPM downloads](https://img.shields.io/npm/dm/webpack-handle-css-loader.svg?style=flat-square)](https://npmjs.com/package/webpack-handle-css-loader) [![Build Status](https://img.shields.io/circleci/project/egoist/webpack-handle-css-loader/master.svg?style=flat-square)](https://circleci.com/gh/egoist/webpack-handle-css-loader) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat-square)](https://github.com/egoist/donate)
|
4 |
|
5 | This is a short-hand module for adding css and extracting css support.
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```bash
|
10 | $ npm install --save webpack-handle-css-loader
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | const HandleCSSLoader = require('webpack-handle-css-loader')
|
17 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
18 |
|
19 | const production = process.env.NODE_ENV === 'production'
|
20 |
|
21 | const handleLoader = new HandleCSSLoader({
|
22 | minimize: production,
|
23 | extract: production
|
24 | })
|
25 |
|
26 | module.exports = {
|
27 | module: {
|
28 | rules: [
|
29 | // Handle .css files with css-loader & postcss-loader
|
30 | handleLoader.css(),
|
31 | // Handle .sass files
|
32 | // Similar to above but add sass-loader too
|
33 | handleLoader.sass()
|
34 | ]
|
35 | },
|
36 | plugins: [
|
37 | new ExtractTextPlugin('[name].[contenthash:8].css')
|
38 | ]
|
39 | }
|
40 | ```
|
41 |
|
42 | ## API
|
43 |
|
44 | ```js
|
45 | const handleLoader = new HandlerCSSLoader()
|
46 | ```
|
47 |
|
48 | ### new HandleCSSLoader([options])
|
49 |
|
50 | #### options
|
51 |
|
52 | ##### minimize
|
53 |
|
54 | Type: `boolean`<br>
|
55 | Default: `undefined`
|
56 |
|
57 | Minimize CSS.
|
58 |
|
59 | ##### extract
|
60 |
|
61 | Type: `boolean`<br>
|
62 | Default: `undefined`
|
63 |
|
64 | Extract CSS.
|
65 |
|
66 | ##### sourceMap
|
67 |
|
68 | Type: `boolean` `string`<br>
|
69 | Default: `undefined`
|
70 |
|
71 | Enable sourcemaps.
|
72 |
|
73 | ##### fallbackLoader
|
74 |
|
75 | Type: `string`<br>
|
76 | Default: `style-loader`
|
77 |
|
78 | ##### cssLoader
|
79 |
|
80 | Type: `string`<br>
|
81 | Default: `css-loader`
|
82 |
|
83 | ##### cssModules
|
84 |
|
85 | Type: `boolean`<br>
|
86 | Default: `undefined`
|
87 |
|
88 | Enable CSS modules.
|
89 |
|
90 | ### handleLoader.getLoader(test, loader, options)
|
91 |
|
92 | #### test
|
93 |
|
94 | Type: `RegExp`
|
95 |
|
96 | #### loader
|
97 |
|
98 | Type: `string`
|
99 |
|
100 | Loader name or the path to it.
|
101 |
|
102 | #### options
|
103 |
|
104 | Type: `any`
|
105 |
|
106 | Loader options.
|
107 |
|
108 | ### handleLoader.css()
|
109 |
|
110 | Alias to `handleLoader.getLoader(/\.css$/, 'css-loader')`
|
111 |
|
112 | ### handleLoader.sass()
|
113 |
|
114 | ### handleLoader.scss()
|
115 |
|
116 | ### handleLoader.stylus()
|
117 |
|
118 | ### handleLoader.styl()
|
119 |
|
120 | ## Contributing
|
121 |
|
122 | 1. Fork it!
|
123 | 2. Create your feature branch: `git checkout -b my-new-feature`
|
124 | 3. Commit your changes: `git commit -am 'Add some feature'`
|
125 | 4. Push to the branch: `git push origin my-new-feature`
|
126 | 5. Submit a pull request :D
|
127 |
|
128 | ## Author
|
129 |
|
130 | **webpack-handle-css-loader** © [EGOIST](https://github.com/egoist), Released under the [MIT](https://egoist.mit-license.org/) License.<br>
|
131 | Authored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/webpack-handle-css-loader/contributors)).
|
132 |
|
133 | > [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)
|