Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'root-relative' urls are not resolved correctly #7

Closed
lettertwo opened this issue Mar 24, 2014 · 10 comments
Closed

'root-relative' urls are not resolved correctly #7

lettertwo opened this issue Mar 24, 2014 · 10 comments

Comments

@lettertwo
Copy link
Contributor

I'm having an issue with webpack failing to resolve a 'root-relative' url for a img src in an html file. When code looks something like (/project/app/index.html):

<img src="/app/assets/img.jpg" />

webpack says:

ModuleNotFoundError: Module not found: Error: Cannot resolve file or directory .//app/assets/img.jpg in /project/app
@lettertwo
Copy link
Contributor Author

I think this issue may apply to other loaders that try to resolve paths from embedded urls as well, such as css-loader and less-loader.

@lettertwo
Copy link
Contributor Author

I think my expectation of how this would work is that the 'root-relative' urls would be resolved against the module root(s). Basically, instead of prepending with ./, stripping the leading / from the the url.

In fact, making the following change to urlToRequire seems to solve my use case:

function urlToRequire(url) {
    if(/^~/.test(url))
        return url.substring(1);
    else if(/^\//.test(url))
        return url.replace(/^\/+/, '');
    else
        return "./"+url;
}

This also seems relevant to the similar functionality in css-loader.

@jhnns
Copy link
Member

jhnns commented Mar 24, 2014

Mhmmm ... I'd expect absolute paths being resolved relative to resolve.root.

@sokra
Copy link
Member

sokra commented Mar 25, 2014

I thought of a query parameter root:

  • root not set: Root-relative urls are threaded like absolute urls and are not translated.
  • root set: root is prepended to root-relative urls and they are translated

@jhnns
Copy link
Member

jhnns commented Mar 29, 2014

Why is it a query parameter? Is it likely to have different roots?

@lettertwo
Copy link
Contributor Author

It doesn't seem very likely that there would be different roots for a given build, but it does seem likely that the root would need to be configured (and differently from resolve.root.) Is there a better way to do that?

@lettertwo
Copy link
Contributor Author

Since #8 is now closed, i think this one can be closed, too!

@jhnns
Copy link
Member

jhnns commented Apr 2, 2014

How does the root-query param work?

@sokra
Copy link
Member

sokra commented Apr 2, 2014

@jhnns
Copy link
Member

jhnns commented Apr 2, 2014

K thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants