fix: only use css modules with \.module\.extension files

This commit is contained in:
Marton Lederer 2021-02-20 14:07:27 +01:00
parent ff270af566
commit 07ef3b6771
No known key found for this signature in database
GPG Key ID: 9B7FD44832ADFE95

View File

@ -42,12 +42,8 @@ const postCSSPlugin = ({
// get a temporary path where we can save compiled CSS // get a temporary path where we can save compiled CSS
const tmpDirPath = tmp.dirSync().name, const tmpDirPath = tmp.dirSync().name,
modulesMap: CSSModule[] = [], modulesMap: CSSModule[] = [],
pathMap: ModulePath[] = []; pathMap: ModulePath[] = [],
modulesPlugin = postcssModules({
// parse css modules with postcss-modules
if (modules !== false) {
plugins.unshift(
postcssModules({
...(typeof modules !== "boolean" ? modules : {}), ...(typeof modules !== "boolean" ? modules : {}),
getJSON(filepath, json, outpath) { getJSON(filepath, json, outpath) {
const tmpFilePath = pathMap.find( const tmpFilePath = pathMap.find(
@ -65,9 +61,7 @@ const postCSSPlugin = ({
) )
return modules.getJSON(filepath, json, outpath); return modules.getJSON(filepath, json, outpath);
} }
}) });
);
}
build.onResolve( build.onResolve(
{ filter: /.\.(css|sass|scss|less|styl)$/, namespace: "file" }, { filter: /.\.(css|sass|scss|less|styl)$/, namespace: "file" },
@ -113,7 +107,9 @@ const postCSSPlugin = ({
).css; ).css;
// wait for plugins to complete parsing & get result // wait for plugins to complete parsing & get result
const result = await postcss(plugins).process(css, { const result = await postcss(
isModule ? [modulesPlugin, ...plugins] : plugins
).process(css, {
from: sourceFullPath, from: sourceFullPath,
to: tmpFilePath to: tmpFilePath
}); });