UNPKG

2.74 kBMarkdownView Raw
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
5This 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
16const cssLoader = require('webpack-handle-css-loader')
17const ExtractTextPlugin = require('extract-text-webpack-plugin')
18
19module.exports = {
20 module: {
21 rules: [
22 // css-loader support
23 // when process.env.NODE_ENV === 'production' css will be extracted into a single file
24 cssLoader(),
25 // similar to above but add sass-loader too
26 cssLoader({loader: 'sass-loader', test: /\.scss$/})
27 ]
28 },
29 plugins: [
30 new ExtractTextPlugin('[name].[contenthash:8].css')
31 ]
32}
33```
34
35## API
36
37### cssLoader([options])
38
39#### options
40
41##### loader
42
43Type: `string`<br>
44Default: `undefined`
45
46The loader you wanna use, eg: `sass-loader` `postcss-loader`, when it's undefined only `style-loader` and `css-loader` will be applied.
47
48### cssLoader:
49
50Type: `string`<br>
51Default: `css-loader?-autoprefixer&sourceMap`
52
53- `-autoprefixer`: you should handle this by yourself, otherwise letting webpack handle it leads to mismatch between development build and production build.
54- `sourceMap`: only have effect when your set `devtool` option in your webpack config.
55
56##### test
57
58Type: `RegExp`<br>
59Default: `/\.css$/`
60
61The regular expression for matching files.
62
63##### env
64
65Type: `string`
66
67Optionally use `env` option if you don't want to set `process.env.NODE_ENV`
68
69## Contributing
70
711. Fork it!
722. Create your feature branch: `git checkout -b my-new-feature`
733. Commit your changes: `git commit -am 'Add some feature'`
744. Push to the branch: `git push origin my-new-feature`
755. Submit a pull request :D
76
77## Author
78
79**webpack-handle-css-loader** © [EGOIST](https://github.com/egoist), Released under the [MIT](https://egoist.mit-license.org/) License.<br>
80Authored and maintained by EGOIST with help from contributors ([list](https://github.com/egoist/webpack-handle-css-loader/contributors)).
81
82> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)