Skip to content

Commit

Permalink
bodged a fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lostfictions committed Jul 26, 2021
1 parent 8427718 commit 03407b2
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
/* eslint no-undef: error */
const withPlugins = require("next-compose-plugins");

const astroturfAltLoaderMatcher = /astroturf\/inline-loader/;

function traverse(rules) {
for (const rule of rules) {
if (typeof rule.loader === "string" && rule.loader.includes("css-loader")) {
if (
rule.options &&
rule.options.modules &&
typeof rule.options.modules.getLocalIdent === "function"
) {
const nextGetLocalIdent = rule.options.modules.getLocalIdent;
rule.options.modules.getLocalIdent = (
context,
localIdentName,
localName,
options
) => {
const nextLocalIdent = nextGetLocalIdent(
context,
localIdentName,
localName,
options
);

return astroturfAltLoaderMatcher.test(context.request)
? `${nextLocalIdent}_${context.resourceQuery.slice(1)}`
: nextLocalIdent;
};
}
}
if (typeof rule.use === "object") {
traverse(Array.isArray(rule.use) ? rule.use : [rule.use]);
}
if (Array.isArray(rule.oneOf)) {
traverse(rule.oneOf);
}
}
}

module.exports = withPlugins(
[
() => ({
Expand All @@ -11,10 +50,12 @@ module.exports = withPlugins(
use: [
{
loader: "astroturf/loader",
// options: { useAltLoader: true },
options: { useAltLoader: true },
},
],
});

traverse(cfg.module.rules);
return cfg;
},
}),
Expand Down

0 comments on commit 03407b2

Please sign in to comment.