Skip to content

Commit

Permalink
Add hashPrefix support option (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessethomson authored and madyankin committed Sep 18, 2019
1 parent f7dd758 commit 6f4d8ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.js
Expand Up @@ -21,7 +21,10 @@ function getScopedNameGenerator(opts) {
const scopedNameGenerator = opts.generateScopedName || generateScopedName;

if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
return genericNames(scopedNameGenerator, { context: process.cwd() });
return genericNames(scopedNameGenerator, {
context: process.cwd(),
hashPrefix: opts.hashPrefix
});
}

function getLoader(opts, plugins) {
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Expand Up @@ -112,6 +112,24 @@ it("processes camelCase option", async () => {
});
});

it("processes hashPrefix option", async () => {
const generateScopedName = "[hash:base64:5]";
const hashPrefix = "prefix";
const getJSON = () => {};

const withoutHashPrefix = plugin({ generateScopedName, getJSON });
const withHashPrefix = plugin({ generateScopedName, getJSON, hashPrefix });

const css = ".foo {}";
const params = { from: "test.css" };

const result1 = await postcss([withoutHashPrefix]).process(css, params);
const result2 = await postcss([withHashPrefix]).process(css, params);

expect(result2.css).toMatchSnapshot("processes hashPrefix option");
expect(result1.css).not.toEqual(result2.css);
});

it("different instances have different generateScopedName functions", async () => {
const one = plugin({
generateScopedName: () => "one",
Expand Down

0 comments on commit 6f4d8ee

Please sign in to comment.