-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
Hey there, I find staticify real handy in a prebuild and deploy scenario, there's just a few issues with replacePaths that mean it doesn't currently work completely for my use case:
- Substrings are often incorrectly replaced
@font-face {
font-family: 'Portrait Web';
src: url('/assets/font-portrait/Portrait-Regular-Web.eot');
src: url('/assets/font-portrait/Portrait-Regular-Web.eot?#iefix') format('embedded-opentype'),
url('/assets/font-portrait/Portrait-Regular-Web.woff2') format('woff2'),
url('/assets/font-portrait/Portrait-Regular-Web.woff') format('woff');
font-weight: 400;
font-style: normal;
font-stretch: normal;
}
Consider CSS that looks like this, if Object.keys returns the woff path before the woff2 path, the hash for the .woff path will actually end up on the .woff2, meaning a broken link in production.
Should be easily fixed with a length sort of Object.keys(versions), so longer strings get handled before shorter strings.
- String.replace only replaces the first instance when used with strings.
Usually not an issue in my builds, but if a file is referenced more than oncereplacePathswon't currently pick it up. Better to turn it into anew RegExp(url, "g"), the global flag will ensure it gets everything.
I think this code should fit the bill but I didn't want to create a pull request and be presumptive, let me know if you want me to create one.
const replacePaths = fileContents => {
return Object.keys(versions).sort(function(a, b) { return b.length - a.length })).reduce((f, url) => {
return f.replace(new RegExp(url, "g"), getVersionedPath(url));
}, fileContents);
};
Cheers!
Metadata
Metadata
Assignees
Labels
No labels