Skip to content

Commit 727173b

Browse files
committed
simple implementation based on postcss
1 parent 01e8eb6 commit 727173b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"main": "index.js",
66
"dependencies": {
77
"css-modules-loader-core": "0.0.11",
8+
"postcss": "^4.1.16",
89
"postcss-modules-extract-imports": "0.0.5",
9-
"postcss-modules-local-by-default": "0.0.11"
10+
"postcss-modules-local-by-default": "0.0.11",
11+
"postcss-modules-scope": "0.0.8"
1012
},
1113
"devDependencies": {
1214
"babel": "^5.8.20",

src/guard.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (global._cssModulesPolyfill) {
4+
throw new Error('only one instance of css-modules/polyfill is allowed');
5+
}
6+
7+
global._cssModulesPolyfill = true;

src/hook.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
/**
4+
* @param {function} compile
5+
*/
6+
module.exports = function (compile) {
7+
require.extensions['.css'] = function (m, filename) {
8+
var tokens = compile(filename);
9+
return m._compile('module.exports = ' + JSON.stringify(tokens), filename);
10+
};
11+
};

src/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
import './guard';
4+
import fs from 'fs';
5+
import hook from './hook';
6+
import postcss from 'postcss';
7+
8+
import extractImports from 'postcss-modules-extract-imports';
9+
import localByDefault from 'postcss-modules-local-by-default';
10+
import scope from 'postcss-modules-scope';
11+
12+
let plugins = [localByDefault, extractImports, scope];
13+
14+
hook(filename => postcss(plugins).process(fs.readFileSync(filename, 'utf8')).css);
15+
16+
/**
17+
* @param {object} opts
18+
* @param {array} opts.u
19+
* @param {array} opts.use
20+
*/
21+
export default function configure(opts) {}

0 commit comments

Comments
 (0)