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
A browserify transform allowing you to `require('styles.css')` and get back locally scoped classnames.
3
+
A browserify transform to load [CSS Modules](https://github.com/css-modules/css-modules).
5
4
6
-
This is based on some ideas around [css-modules](http://github.com/css-modules), but not yet as fully-featured.
5
+
** Please note that this is still highly experimental. **
7
6
8
-
Why local css?
9
-
----
7
+
## Why CSS Modules?
10
8
11
-
Normally you need to use a strict naming convention like BEM to ensure that one component's CSS doesn't collide with another's. Locally-scoped css allows you to use names that are meaningful within the context of the component, without any danger of name collision.
9
+
Normally you need to use a strict naming convention like BEM to ensure that one component's CSS doesn't collide with another's. CSS Modules are locally scoped, which allows you to use names that are meaningful within the context of the component, without any danger of name collision.
12
10
13
11
Read Mark Dalgleish's excellent ["End of Global CSS"](https://medium.com/seek-ui-engineering/the-end-of-global-css-90d2a4a06284) and check out [css-modules](http://github.com/css-modules) for more context.
14
12
15
-
Usage
16
-
----
13
+
## Usage
17
14
18
-
First install the package: `npm install --save local-css`
15
+
First install the package: `npm install --save css-modulesify`
19
16
20
-
Then you can use it as a browserify transform, eg: `browserify -t local-css example/index.js`
17
+
Then you can use it as a browserify transform, eg: `browserify -t css-modulesify example/index.js`
21
18
22
19
Inside `example/index.js` you can now load css into your scripts. When you do `var box1 = require('./box1.css')`, `box1` will be an object to lookup the localized classname for one of the selectors in that file.
23
20
@@ -31,21 +28,21 @@ var div = `<div class="${styles.inner}">...</div>`;
31
28
To add the css to the html page there are 2 easy options:
32
29
33
30
- add the css to the DOM at runtime (good for component-based css): `require('insert-css')(require('./styles.css'))`
34
-
- export a static css file at build-time: `browserify -t local-css example/export-css.js | node > bundle.css`
31
+
- export a static css file at build-time: `browserify -t css-modulesify example/export-css.js | node > bundle.css`
35
32
36
-
Example
37
-
----
33
+
## Example
38
34
39
-
Take a look at the [example](./example/index.js) for more details, or [inspect the source](http://joshwnj.github.io/local-css/).
35
+
Take a look at the [example](./example/index.js) for more details, or [inspect the source](https://css-modules.github.io/css-modulesify/).
40
36
41
37
42
-
Licence
43
-
----
38
+
## Licence
44
39
45
40
MIT
46
41
47
42
48
-
Thanks and inspiration
49
-
----
43
+
## Thanks and inspiration
50
44
51
45
To all the fine folk working on [css-modules](https://github.com/css-modules)
0 commit comments