fix: only use css modules with \.module\.extension files
This commit is contained in:
parent
ff270af566
commit
07ef3b6771
46
src/index.ts
46
src/index.ts
@ -42,32 +42,26 @@ 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({
|
||||||
|
...(typeof modules !== "boolean" ? modules : {}),
|
||||||
|
getJSON(filepath, json, outpath) {
|
||||||
|
const tmpFilePath = pathMap.find(
|
||||||
|
({ originalPath }) => originalPath === filepath
|
||||||
|
).temporaryPath;
|
||||||
|
|
||||||
// parse css modules with postcss-modules
|
modulesMap.push({
|
||||||
if (modules !== false) {
|
path: tmpFilePath,
|
||||||
plugins.unshift(
|
map: json
|
||||||
postcssModules({
|
});
|
||||||
...(typeof modules !== "boolean" ? modules : {}),
|
|
||||||
getJSON(filepath, json, outpath) {
|
|
||||||
const tmpFilePath = pathMap.find(
|
|
||||||
({ originalPath }) => originalPath === filepath
|
|
||||||
).temporaryPath;
|
|
||||||
|
|
||||||
modulesMap.push({
|
if (
|
||||||
path: tmpFilePath,
|
typeof modules !== "boolean" &&
|
||||||
map: json
|
typeof modules.getJSON === "function"
|
||||||
});
|
)
|
||||||
|
return modules.getJSON(filepath, json, outpath);
|
||||||
if (
|
}
|
||||||
typeof modules !== "boolean" &&
|
});
|
||||||
typeof modules.getJSON === "function"
|
|
||||||
)
|
|
||||||
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
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user