newer-universal-style-loader/README.md

55 lines
1.5 KiB
Markdown
Raw Normal View History

2012-04-07 05:06:57 +04:00
# style loader for webpack
## Usage
2014-03-11 22:40:59 +04:00
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
2014-01-27 14:41:56 +04:00
### Simple API
2012-04-07 05:06:57 +04:00
``` javascript
2012-07-17 04:11:39 +04:00
require("style!raw!./file.css");
2012-04-07 05:06:57 +04:00
// => add rules in file.css to document
```
2014-01-27 14:41:56 +04:00
It's recommended to combine it with the [`css-loader`](https://github.com/webpack/css-loader): `require("style!css!./file.css")`.
2012-07-17 04:11:39 +04:00
2013-03-26 14:51:42 +04:00
It also possible to add a URL instead of a css string:
``` javascript
require("style/url!file!./file.css");
// => add a <link rel="stlyesheet"> to file.css to document
```
2014-01-27 14:41:56 +04:00
### Reference-counted API
``` javascript
var style = require("style/useable!css!./file.css");
style.use(); // = style.ref();
style.unuse(); // = style.unref();
```
Styles are not added on require, but instead on call to `use`/`ref`. Styles are removed from page if `unuse`/`unref` is called exactly as often as `use`/`ref`.
Note: Behavior is undefined when `unuse`/`unref` is called more often than `use`/`ref`. Don't do that.
2014-03-01 19:50:30 +04:00
## Recommended configuration
By convention the reference-counted API should be bound to `.useable.css` and the simple API to `.css` (similar to other file types, i. e. `.useable.less` and `.less`).
So the recommended configuration for webpack is:
``` javascript
{
module: {
loaders: [
{ test: /\.css$/, exclude: /\.useable\.css$/, loader: "style!css" },
{ test: /\.useable\.css$/, loader: "style/useable!css" }
]
}
}
```
2012-04-07 05:06:57 +04:00
## License
2014-03-01 19:50:30 +04:00
MIT (http://www.opensource.org/licenses/mit-license.php)