Skip to content

Commit b5c2aa8

Browse files
committed
Merge pull request #49 from css-modules/wp
Wp
2 parents fc1d98b + 76c4b56 commit b5c2aa8

File tree

8 files changed

+67
-2
lines changed

8 files changed

+67
-2
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ coverage
33
node_modules
44

55
generate-tests.js
6+
test/cases/webpack/*
67
test/common-test-cases.js
8+
webpack.config.js

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ generate-tests.js
77
src/
88
test/
99
utils/
10+
webpack.config.js

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"debug": "^2.2.0",
11-
"generic-names": "^1.0.0",
11+
"generic-names": "^1.0.1",
1212
"icss-replace-symbols": "^1.0.2",
1313
"lodash.foreach": "^3.0.3",
1414
"lodash.identity": "^3.0.0",
@@ -19,21 +19,26 @@
1919
"devDependencies": {
2020
"babel": "^5.8.20",
2121
"babel-eslint": "^4.0.5",
22+
"css-loader": "^0.21.0",
2223
"css-modules-loader-core": "^1.0.0",
2324
"eslint": "^1.0.0",
2425
"eslint-config-airbnb": "0.0.7",
2526
"eslint-config-airbnb-lite": "^1.0.3",
2627
"eslint-watch": "^1.2.4",
28+
"extract-text-webpack-plugin": "^0.8.2",
2729
"in-publish": "^2.0.0",
2830
"isparta": "^3.0.3",
2931
"lodash": "^3.10.1",
3032
"mocha": "^2.2.5",
3133
"postcss": "^5.0.10",
34+
"postcss-loader": "^0.7.0",
3235
"postcss-modules-extract-imports": "^1.0.0",
3336
"postcss-modules-local-by-default": "^1.0.0",
3437
"postcss-modules-scope": "^1.0.0",
3538
"postcss-modules-values": "^1.1.0",
36-
"precommit-hook": "^3.0.0"
39+
"precommit-hook": "^3.0.0",
40+
"style-loader": "^0.13.0",
41+
"webpack": "^1.12.2"
3742
},
3843
"peerDependencies": {
3944
"postcss": "^5.x",
@@ -43,6 +48,7 @@
4348
"postcss-modules-values": "^1.1.0"
4449
},
4550
"scripts": {
51+
"fixture": "webpack",
4652
"start": "esw -w .",
4753
"lint": "eslint .",
4854
"test": "mocha --compilers js:babel/register",

test/cases/webpack/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
result*

test/cases/webpack/source.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.local
2+
{
3+
color: white;
4+
}

test/cases/webpack/source.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var css = require('./source.css');

test/extractor.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { equal } from 'assert';
2+
import { execSync } from 'child_process';
3+
import { readFileSync } from 'fs';
4+
import { resolve } from 'path';
5+
import hook from '../src';
6+
7+
describe('extractor', () => {
8+
let selector;
9+
10+
before(() => {
11+
hook({generateScopedName: '[name]__[local]___[hash:base64:5]'});
12+
execSync('npm run fixture', {cwd: process.cwd()});
13+
selector = readFileSync(resolve('test/cases/webpack/result.css'), 'utf8')
14+
.split('\n').shift().replace(/^\./, '');
15+
});
16+
17+
it('should generate the same selectors as the webpack does', () => {
18+
const tokens = require('./cases/webpack/source.css');
19+
equal(selector, tokens.local);
20+
});
21+
});

webpack.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
4+
var path = require('path');
5+
6+
module.exports = {
7+
entry: path.resolve('test/cases/webpack/source.js'),
8+
9+
output: {
10+
filename: 'result.js',
11+
path: path.resolve('test/cases/webpack')
12+
},
13+
14+
module: {
15+
loaders: [
16+
{
17+
test: /\.css$/,
18+
loader: ExtractTextPlugin.extract('style-loader',
19+
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader')
20+
}
21+
]
22+
},
23+
24+
plugins: [
25+
new ExtractTextPlugin('result.css', {
26+
allChunks: true
27+
})
28+
]
29+
};

0 commit comments

Comments
 (0)