Skip to content

Commit 6f4d8ee

Browse files
jessethomsonmadyankin
authored andcommitted
Add hashPrefix support option (#98)
1 parent f7dd758 commit 6f4d8ee

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function getScopedNameGenerator(opts) {
2121
const scopedNameGenerator = opts.generateScopedName || generateScopedName;
2222

2323
if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
24-
return genericNames(scopedNameGenerator, { context: process.cwd() });
24+
return genericNames(scopedNameGenerator, {
25+
context: process.cwd(),
26+
hashPrefix: opts.hashPrefix
27+
});
2528
}
2629

2730
function getLoader(opts, plugins) {

test/test.js

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ it("processes camelCase option", async () => {
112112
});
113113
});
114114

115+
it("processes hashPrefix option", async () => {
116+
const generateScopedName = "[hash:base64:5]";
117+
const hashPrefix = "prefix";
118+
const getJSON = () => {};
119+
120+
const withoutHashPrefix = plugin({ generateScopedName, getJSON });
121+
const withHashPrefix = plugin({ generateScopedName, getJSON, hashPrefix });
122+
123+
const css = ".foo {}";
124+
const params = { from: "test.css" };
125+
126+
const result1 = await postcss([withoutHashPrefix]).process(css, params);
127+
const result2 = await postcss([withHashPrefix]).process(css, params);
128+
129+
expect(result2.css).toMatchSnapshot("processes hashPrefix option");
130+
expect(result1.css).not.toEqual(result2.css);
131+
});
132+
115133
it("different instances have different generateScopedName functions", async () => {
116134
const one = plugin({
117135
generateScopedName: () => "one",

0 commit comments

Comments
 (0)