Skip to content

Commit 35c0623

Browse files
committed
Merge pull request #59 from css-modules/beta
Beta
2 parents 3555387 + ac0edf3 commit 35c0623

File tree

124 files changed

+1642
-1409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1642
-1409
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
]
5+
}

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
# cheat sheet: http://EditorConfig.org

.eslintignore

-8
This file was deleted.

.eslintrc

-11
This file was deleted.

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ node_modules/*
2828

2929
# added automatically by precommit-hook as defaults
3030
.jshint*
31-
32-
dist/
33-
!node_modules/awesome-theme

.npmignore

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Generated by dmn (https://github.com/inikulin/dmn)
2-
3-
.git*
1+
.babelrc
2+
.editorconfig
3+
.gitignore
44
.npmignore
55
.travis.yml
6-
generate-tests.js
7-
src/
8-
test/
9-
utils/
10-
webpack.config.js
6+
coverage
7+
demo

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
language: node_js
22
node_js:
3-
- "4.1"
4-
- "0.12"
3+
- "4.3"

README.md

+34-18
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ Compiling in runtime, [universal](https://medium.com/@mjackson/universal-javascr
1414

1515
## Requirements
1616

17-
To use this tool we require [Node.js v0.12.x](https://github.com/nodejs/node) (or higher) and several modules to be installed.
18-
19-
- [postcss](https://github.com/postcss/postcss) version 5 or higher
20-
- [postcss-modules-values](https://github.com/css-modules/postcss-modules-values)
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)
17+
To use this tool we require [Node.js v0.12.x](https://github.com/nodejs/node) (or higher).
2418

2519
## Installation
2620

@@ -30,28 +24,45 @@ $ npm i css-modules-require-hook
3024

3125
## Usage
3226

33-
In this section I've tried to cover the common cases of usage.
27+
Now, there are two ways to attach hook: manually or using preset file.
3428

35-
### Development mode
29+
The first one allows you to pass options manually after module was required. Example:
3630

37-
Usually, Node.js caches all the `require` calls by default. In order to invalidate cache for the purpose of development you should set the environment variable `NODE_ENV` to `development`. For example:
31+
```javascript
32+
const hook = require('css-modules-require-hook');
3833

39-
```bash
40-
$ NODE_ENV=development node server.js
41-
```
34+
hook({
35+
generateScopedName: '[name]__[local]___[hash:base64:5]',
36+
});
4237

43-
Still you can use `devMode` option (see below) to override behavior which is imposed by environment variable.
38+
// const styles = require('./icon.css');
39+
```
4440

45-
### Basic example
41+
The second one allows you to move options to the separate file `cmrh.conf.js`. Config file should be located in the same directory where executor is or in its ancestor directories. In that case hook will be attached right after the `css-modules-require-hook/preset` module will be required. Example:
4642

47-
Basically to attach the require hook you need to require this module. If you need to adjust it see the tuning section below.
43+
```javascript
44+
// cmrh.conf.js
45+
module.exports = {
46+
generateScopedName: '[name]__[local]___[hash:base64:5]',
47+
};
48+
```
4849

4950
```javascript
50-
require('css-modules-require-hook');
51+
require('css-modules-require-hook/preset');
5152

52-
// var styles = require('./icon.css');
53+
// const styles = require('./icon.css');
5354
```
5455

56+
### Development mode
57+
58+
Usually, Node.js caches all the `require` calls by default. In order to invalidate cache for the purpose of development you should set the environment variable `NODE_ENV` to `development`. For example:
59+
60+
```bash
61+
$ NODE_ENV=development node server.js
62+
```
63+
64+
Still you can use `devMode` option (see below) to override behavior which is imposed by environment variable.
65+
5566
### Adding custom PostCSS plugins
5667

5768
```javascript
@@ -166,6 +177,10 @@ hook({
166177

167178
Attach the require hook to additional file extensions (for example `['.scss']`).
168179

180+
### `ignore` function|regex|string
181+
182+
Provides possibility to exclude particular files from processing. Supports glob and regular expressions syntax. Also you may provide custom function.
183+
169184
### `rootDir` string
170185

171186
Provides 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.
@@ -213,6 +228,7 @@ Short alias for the [postcss-modules-local-by-default](https://github.com/css-mo
213228

214229
[debug](https://www.npmjs.com/package/debug) package is used for debugging. So to turn it on simply specify the **DEBUG** environment variable:
215230
- `DEBUG=css-modules:fetch` — to see resolved paths to the files.
231+
- `DEBUG=css-modules:preset` — to see whether config was found or not.
216232
- `DEBUG=css-modules:setup` — to see the new options list.
217233
- `DEBUG=css-modules:*` — to see everything.
218234

demo/.babelrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [
3+
"es2015",
4+
"react",
5+
"stage-0"
6+
]
7+
}

0 commit comments

Comments
 (0)