From 76cd917c94e7c3ca6e55f17dc9cc4c5b34b8e8d3 Mon Sep 17 00:00:00 2001 From: jesset Date: Fri, 13 Sep 2019 10:43:28 -0600 Subject: [PATCH] Add hashPrefix support option --- src/index.js | 5 ++++- test/test.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2b6a4f3..63a1058 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { diff --git a/test/test.js b/test/test.js index ffd6154..a2d54c1 100644 --- a/test/test.js +++ b/test/test.js @@ -118,6 +118,23 @@ test("processes camelCase option", async t => { }); }); +test("processes hashPrefix option", async t => { + 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); + + t.not(result1.css, result2.css); +}); + test("different instances have different generateScopedName functions", async t => { const one = plugin({ generateScopedName: () => "one",