Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashPrefix option #98

Merged
merged 2 commits into from Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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