23 lines
626 B
TypeScript
23 lines
626 B
TypeScript
|
import Postcss from "postcss";
|
||
|
import { readAssetManifest } from "../hash.js";
|
||
|
|
||
|
export default (opts: any = {}): Postcss.Plugin => {
|
||
|
return {
|
||
|
postcssPlugin: "postcss-hashes",
|
||
|
Once() {
|
||
|
opts._mappings = readAssetManifest();
|
||
|
},
|
||
|
Declaration(decl: Postcss.Declaration) {
|
||
|
decl.value = decl.value.replace(/url\("([^"]+)"\)/, (v, url) => {
|
||
|
if (opts._mappings.hasOwnProperty(url)) {
|
||
|
return v.replace(url, opts._mappings[url]);
|
||
|
}
|
||
|
|
||
|
return v;
|
||
|
});
|
||
|
},
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export const postcss = true;
|