Closed callumlocke closed 8 years ago
Related to #118. Reopened it.
I'm not sure if this bug can be addressed with the base
option, because a project might contain multiple files at various different levels, whereas the base
option applies to everything (if I understand correctly).
The solution is to resolve all file-relative asset paths relative to the dirname of the referring HTML file (i.e. what browsers do). Only root-relative asset paths (those starting with /
) should be resolved relative to the vinyl base.
Anybody want to write a test case?
Change 9906172 should fix this issue.
Should be fixed in the next release.
@jonkemp, great, this fix works! -Thank you!
Directory structure:
Code:
Both the HTML files load the same
main.css
file, using relative paths:index.html
:<link rel="stylesheet" href="styles/main.css">
extra.html
:<link rel="stylesheet" href="../styles/main.css">
This works fine in the browser. But when I use
gulp-useref
, when it's processingextra.html
it gives this error:Error: Error: File not found with singular glob: ~/code/my-project/styles/main.css
(note that it has climbed right up out of thesrc
directory).It looks like useref is ignoring the fact that
extra.html
is one level deeper than thesrc
root, and just always searches for assets relative to the root (rather than relative to dirname of the actual HTML file).I tried changing the link tag in
extra.html
to remove the../
, and this helps useref to find the file, but it means my code doesn't work in development before useref.I've tried setting
base
to"dist"
but it makes no difference.The same incorrect assumption (that all HTML files are at root) seems to apply to the path in a build block comment too – a relative output path like
<!-- build:css ../styles/.bundle.css -->
actually writes the file right outside my project.