Skip to content

Commit 9ba7cf2

Browse files
committed
Update README with links to DOM and React usage of camelCase style
objects. Add 'Use Cases' section. Fix 'scss' regex. Formatting.
1 parent 2428e40 commit 9ba7cf2

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# css-object-loader
66

7-
Webpack loader to load CSS into a selector object with camelCased properties. Load a CSS file and it will return an object with keys that are the selectors from that CSS file. Each selector has an object containing the rules declared in your CSS.
7+
Webpack loader to load CSS into an object. The object has keys that are selectors from the CSS file; the value of each selector are the rules converted to camelCase properties ([see Style Object Properties](http://www.w3schools.com/jsref/dom_obj_style.asp)). This object is compatible with [React Inline Styles](https://facebook.github.io/react/tips/inline-styles.html).
88

99
## Install
1010

@@ -17,14 +17,14 @@ Webpack loader to load CSS into a selector object with camelCased properties. Lo
1717
Create an entry to load `.css` files in your webpack.config:
1818

1919
```js
20-
module: {
21-
loaders: [{
22-
test: /\.css$/,
23-
loaders: [ 'css-object' ],
24-
exclude: /node_modules/
25-
}
26-
]
27-
}
20+
module: {
21+
loaders: [{
22+
test: /\.css$/,
23+
loaders: [ 'css-object' ],
24+
exclude: /node_modules/
25+
}
26+
]
27+
}
2828
```
2929

3030
Requiring CSS rules:
@@ -72,20 +72,24 @@ const MyComponent = ({children}) => (
7272
###### DOM
7373
```js
7474
function applyStylesToNode (styles, node) {
75-
Object.keys(styles).forEach(key => node.style[key] = styles[key]);
76-
return node;
75+
Object.keys(styles).forEach(key => { node.style[key] = styles[key] });
7776
}
7877
applyStylesToNode(selectors['.centered'], document.querySelector('#some-div'));
7978
```
8079

80+
### Use Case
81+
82+
1. You want to inline all your styles, but you still want to write your CSS into CSS files.
83+
2. You want to use a CSS preprocessor to write your inline styles.
84+
8185
### Multiple Loaders
8286

8387
If you want to use `css-object-loader` with LESS or SASS, make sure the preprocessor loader runs before `css-object-loader`. Webpack evaluates loaders right to left. Example config for SASS:
8488

8589
```js
8690
module: {
8791
loaders: [{
88-
test: /\.scss/,
92+
test: /\.scss$/,
8993
loaders: [ 'css-object', 'sass' ],
9094
exclude: /node_modules/
9195
}]
@@ -94,7 +98,11 @@ module: {
9498

9599
## Limitations
96100

97-
This library uses [reworkcss/css](https://github.com/reworkcss/css) to parse CSS. It is currently a proof of concept and not intended for production usage. This loader should function with other CSS preprocessors as long as they run before `css-object-loader`. The underlying concept is still a work in progress, if you have any suggestions please feel free to open an issue.
101+
This library is currently a proof of concept and not intended for production usage. This loader should function with other CSS preprocessors as long as they run before `css-object-loader`. The underlying concept is still a work in progress, if you have any suggestions please feel free to open an issue.
102+
103+
## Implementation
104+
105+
This library uses [reworkcss/css](https://github.com/reworkcss/css) to parse CSS to an AST. The AST is then traversed to find rule declarations and populate them into an object. Media queries are ignored.
98106

99107
## Contributing
100108

0 commit comments

Comments
 (0)