Skip to content

Commit 5191da0

Browse files
committed
Merge pull request #31 from css-modules/readme
review
2 parents 56f2b91 + 9d44f83 commit 5191da0

File tree

1 file changed

+53
-37
lines changed

1 file changed

+53
-37
lines changed

README.md

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,83 @@
11
css-modules-require-hook
22
========================
33

4-
Automatically compiles a CSS Module to a low-level interchange format called ICSS or [Interoperable CSS](https://github.com/css-modules/icss).
4+
The require hook compiles [CSS Modules](https://github.com/css-modules/css-modules) in runtime. This is similar to Babel's [babel/register](https://babeljs.io/docs/usage/require/).
55

6-
One of the ways you can compile [CSS Modules](https://github.com/css-modules/css-modules) to the ICSS format is through the require hook. The require hook will bind itself to node's require and automatically compile files on the fly. This is similar to Babel's [babel/register](https://babeljs.io/docs/usage/require/).
6+
## What is CSS Modules
77

8-
## Requirements
8+
A **CSS Module** is a CSS file in which all class names and animation names are scoped locally by default. Learn more in the article [CSS Modules - Welcome to the Future](http://glenmaddern.com/articles/css-modules) by Glen Maddern.
99

10-
To use this tool we require postcss and few plugins to be installed on your project. See the list below:
10+
## Features
1111

12-
- `"postcss": "4.x"`
13-
- `"postcss-modules-extract-imports": "0.x"`
14-
- `"postcss-modules-local-by-default": "0.x"`
15-
- `"postcss-modules-scope": "0.x"`
16-
17-
## Install
18-
19-
```bash
20-
$ npm i css-modules-require-hook
21-
```
12+
Compiling in runtime, [universal](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) usage.
2213

2314
## Usage
2415

25-
```javascript
26-
require('css-modules-require-hook');
27-
```
16+
### Requirements
2817

29-
## Available options
18+
To use this tool we require [Node.js v0.12.x](https://github.com/nodejs/node) (or higher) and several modules to be installed.
3019

31-
Providing additional options allows you to get advanced experience. See the variants below.
20+
- [postcss](https://github.com/postcss/postcss) version 4 or higher
21+
- [postcss-modules-extract-imports](https://github.com/css-modules/postcss-modules-extract-imports)
22+
- [postcss-modules-local-by-default](https://github.com/css-modules/postcss-modules-local-by-default)
23+
- [postcss-modules-scope](https://github.com/css-modules/postcss-modules-scope)
3224

33-
```javascript
34-
var hook = require('css-modules-require-hook');
35-
hook({ /* options */ });
36-
```
25+
### Installation
3726

38-
### `rootDir` option
27+
```bash
28+
$ npm i css-modules-require-hook
29+
```
3930

40-
Aliases are `root`, `d`.
31+
### Tuning (options)
4132

42-
Absolute path to your project's root directory. This is optional but providing it will result in better generated classnames. It can be obligatory, if you run require hook and build tools, like [css-modulesify](https://github.com/css-modules/css-modulesify) from different working directories.
33+
* `function` **createImportedName** — short alias for the [postcss-modules-extract-imports](https://github.com/css-modules/postcss-modules-extract-imports) plugin's `createImportedName` option.
34+
* `function` **generateScopedName** — short alias for the [postcss-modules-scope](https://github.com/css-modules/postcss-modules-scope) plugin's option. Helps you to specify the custom way to build generic names for the class selectors.
35+
* `function` **processCss** — in rare cases you may want to get compiled styles in runtime, so providing this option helps.
36+
* `string` **rootDir** — absolute path to the project directory. Providing this will result in better generated class names. It can be obligatory, if you run require hook and build tools (like [css-modulesify](https://github.com/css-modules/css-modulesify)) from different working directories.
37+
* `string` **to** — provides `to` option to the [LazyResult instance](https://github.com/postcss/postcss/blob/master/docs/api.md#processorprocesscss-opts).
38+
* `array` **use** — custom subset of postcss plugins.
4339

44-
### `use` option
40+
### Examples
4541

46-
Alias is `u`.
42+
Basically you need to require this plugin before other requires for your styles will occur.
43+
For example:
4744

48-
Custom list of plugins. This is optional but helps you to extend list of basic [postcss](https://github.com/postcss/postcss) plugins. Also helps to specify options for particular plugins.
45+
*icon.css*
46+
```css
47+
.icon
48+
{
49+
composes: fa fa-hand-peace-o from 'font-awesome/css/font-awesome.css';
50+
}
51+
```
4952

50-
### `createImportedName` option
53+
*server.js*
54+
```javascript
55+
require('css-modules-require-hook');
5156

52-
Alias for the `createImportedName` option from the [postcss-modules-extract-imports](https://github.com/css-modules/postcss-modules-extract-imports) plugin. This is optional. Won't work if you `use` option.
57+
var styles = require('./icon.css');
58+
var html = '<i class="' + styles.icon + '"></i>';
59+
// send it somehow :)
60+
```
5361

54-
### `generateScopedName` option
62+
You'll get:
5563

56-
Custom function to generate class names. This is optional. Alias for the `generateScopedName` option from the [postcss-modules-scope](https://github.com/css-modules/postcss-modules-scope) plugin. Won't work if you `use` option.
64+
```html
65+
<i class="_icon_font-awesome-css-font-awesome__fa _icon_font-awesome-css-font-awesome__fa-hand-peace-o"></i>'
66+
```
5767

58-
### `mode` option
68+
In rare cases you may want to tune the require hook for better experience.
5969

60-
Alias for the `mode` option from the [postcss-modules-local-by-default](https://github.com/css-modules/postcss-modules-local-by-default) plugin. This is optional. Won't work if you `use` option.
70+
```javascript
71+
var hook = require('css-modules-require-hook');
72+
var path = require('path');
6173

62-
## Examples
74+
hook({
75+
// setting root to the parent directory
76+
rootDir: path.join(__dirname, '..')
77+
});
78+
```
6379

64-
If you want to add custom functionality, for example [CSS Next](http://cssnext.io/setup/#as-a-postcss-plugin) plugin, you should provide the `use` option.
80+
If you want to add any postcss plugins to the pipeline - you should use the `use` option.
6581

6682
```javascript
6783
var hook = require('css-modules-require-hook');

0 commit comments

Comments
 (0)