Fix map not updating when using watch files

This commit is contained in:
g45t345rt 2021-03-31 14:48:29 -04:00
parent 81d1e9ea77
commit d798528ba6
3 changed files with 29 additions and 13 deletions

13
dist/index.esm.js vendored
View File

@ -19,10 +19,15 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]",
...typeof modules !== "boolean" ? modules : {},
getJSON(filepath, json, outpath) {
modulesMap.push({
path: filepath,
map: json
});
const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
if (mapIndex !== -1) {
modulesMap[mapIndex].map = json;
} else {
modulesMap.push({
path: filepath,
map: json
});
}
if (typeof modules !== "boolean" && typeof modules.getJSON === "function")
return modules.getJSON(filepath, json, outpath);
}

13
dist/index.js vendored
View File

@ -45,10 +45,15 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]",
...typeof modules !== "boolean" ? modules : {},
getJSON(filepath, json, outpath) {
modulesMap.push({
path: filepath,
map: json
});
const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
if (mapIndex !== -1) {
modulesMap[mapIndex].map = json;
} else {
modulesMap.push({
path: filepath,
map: json
});
}
if (typeof modules !== "boolean" && typeof modules.getJSON === "function")
return modules.getJSON(filepath, json, outpath);
}

View File

@ -43,10 +43,16 @@ const postCSSPlugin = ({
generateScopedName: "[name]__[local]___[hash:base64:5]",
...(typeof modules !== "boolean" ? modules : {}),
getJSON(filepath, json, outpath) {
modulesMap.push({
path: filepath,
map: json
});
// Make sure to replace json map instead of pushing new map everytime with edit file on watch
const mapIndex = modulesMap.findIndex((m) => m.path === filepath);
if (mapIndex !== -1) {
modulesMap[mapIndex].map = json;
} else {
modulesMap.push({
path: filepath,
map: json
});
}
if (
typeof modules !== "boolean" &&
@ -62,7 +68,7 @@ const postCSSPlugin = ({
// Namespace is empty when using CSS as an entrypoint
if (args.namespace !== "file" && args.namespace !== "") return;
// Resolve files also from node_modules (ex: npm normalize.css)
// Resolve files from node_modules (ex: npm install normalize.css)
let sourceFullPath = resolveFile(args.path);
if (!sourceFullPath)
sourceFullPath = path.resolve(args.resolveDir, args.path);