Skip to content

Commit baab9ef

Browse files
committed
Merge pull request webpack-contrib#146 from webpack/values
added CSS Modules values support
2 parents d1aa291 + 6f9de76 commit baab9ef

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

lib/processCss.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var getLocalIdent = require("./getLocalIdent");
1111
var localByDefault = require("postcss-modules-local-by-default");
1212
var extractImports = require("postcss-modules-extract-imports");
1313
var modulesScope = require("postcss-modules-scope");
14+
var modulesValues = require("postcss-modules-values");
1415
var cssnano = require("cssnano");
1516

1617
var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
@@ -144,6 +145,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
144145
}
145146
}),
146147
extractImports(),
148+
modulesValues,
147149
modulesScope({
148150
generateScopedName: function(exportName) {
149151
return getLocalIdent(options.loaderContext, localIdentName, exportName, {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"lodash.camelcase": "^3.0.1",
1212
"postcss": "^5.0.6",
1313
"postcss-modules-extract-imports": "1.0.0-beta2",
14-
"postcss-modules-local-by-default": "1.0.0-beta1",
14+
"postcss-modules-local-by-default": "1.0.0-beta2",
1515
"postcss-modules-scope": "1.0.0-beta2",
16+
"postcss-modules-values": "^1.1.0",
1617
"source-list-map": "^0.1.4"
1718
},
1819
"devDependencies": {
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
._a_ {
2+
background: red;
3+
background: green;
4+
background: red;
5+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@value aaa: red;
2+
@value bbb: green;
3+
@value ccc: aaa;
4+
5+
.a {
6+
background: aaa;
7+
background: bbb;
8+
background: ccc;
9+
}

test/valuesTest.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*globals describe */
2+
3+
var testLocals = require("./helpers").testLocals;
4+
var test = require("./helpers").test;
5+
6+
function testLocal(name, input, result, localsResult, query, modules) {
7+
result.locals = localsResult;
8+
test(name, input, result, query, modules);
9+
}
10+
11+
describe("values", function() {
12+
testLocals("should export values",
13+
"@value def: red; @value ghi: 1px solid black",
14+
{
15+
def: "red",
16+
ghi: "1px solid black"
17+
},
18+
""
19+
);
20+
testLocals("should export values and locals",
21+
"@value def: red; .ghi { color: def; }",
22+
{
23+
def: "red",
24+
ghi: "_ghi"
25+
},
26+
"?modules&localIdentName=_[local]"
27+
);
28+
testLocal("should import values from other module",
29+
"@value def from './file'; .ghi { color: def; }", [
30+
[ 2, "", "" ],
31+
[ 1, ".ghi { color: red; }", "" ]
32+
], {
33+
def: "red"
34+
}, "", {
35+
"./file": (function() {
36+
var a = [[2, "", ""]];
37+
a.locals = {
38+
def: "red"
39+
};
40+
return a;
41+
})()
42+
}
43+
);
44+
testLocal("should import values with renaming",
45+
"@value def as aaa from './file1'; @value def as bbb from './file2'; .ghi { background: aaa, bbb, def; }", [
46+
[ 2, "", "" ],
47+
[ 3, "", "" ],
48+
[ 1, ".ghi { background: red, green, def; }", "" ]
49+
], {
50+
aaa: "red",
51+
bbb: "green"
52+
}, "", {
53+
"./file1": (function() {
54+
var a = [[2, "", ""]];
55+
a.locals = {
56+
def: "red"
57+
};
58+
return a;
59+
})(),
60+
"./file2": (function() {
61+
var a = [[3, "", ""]];
62+
a.locals = {
63+
def: "green"
64+
};
65+
return a;
66+
})()
67+
}
68+
);
69+
});

0 commit comments

Comments
 (0)