Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Using file-loader with __webpack_public_path__? #125

Closed
silouanwright opened this issue Feb 16, 2017 · 10 comments
Closed

Using file-loader with __webpack_public_path__? #125

silouanwright opened this issue Feb 16, 2017 · 10 comments

Comments

@silouanwright
Copy link

silouanwright commented Feb 16, 2017

Using the latest version of file-loader. The following works for me:

file-loader?name=img/[name].[ext]&emitFile=false&publicPath=/xyz/

Because the publicPath for my application can vary wildly, I can't hardcode the publicPath in the webpack config. I'd like if the file-loader used __webpack_public_path__ or had some option like [webpack_public_path] or basically any hook I could use to be able to let my backend specify what the publicPath is.

Any ideas? Is this something I can get around for now? I feel like this is either a bug, or a feature, or a question... I don't know enough to say.

@krtools
Copy link

krtools commented Mar 2, 2017

Hey, was having the same issue but was able to work it out for my use case.

This didn't work

// index.js
__webpack_public_path__ = '...';
.
.
.
import Main from '.../Main';

However this did:

// setPublicPath.js
__webpack_public_path__ = '...';
// index.js:
import './setPublicPath';
.
.
.
import Main from '.../Main';
...

All the ES6 imports were ran before any actual code, regardless of order, so the URLs in any (recursively) imported files were resolved before the public path was set. So setting the public path in another import before any other imports ensured the correct path for everything else.

Hope this helps.

@silouanwright
Copy link
Author

That doesn't work for me. I'm curious if anyone else has this issue.

@lili21
Copy link

lili21 commented Apr 18, 2017

file-loader will use __webpack_public_path__ by default. so You don't need to set publicPath for file-loader

@lili21
Copy link

lili21 commented Apr 18, 2017

@reywright webpack/webpack#2776

@lili21
Copy link

lili21 commented Apr 18, 2017

actually, the publicPath config will override __webpack_public_path__. I guess that's the problem. @reywright

@silouanwright
Copy link
Author

@lili21 what I'm saying is I need to specify the publicPath because the publicPath doesn't work otherwise. I've seen those threads you're talking about... I'll try them again but I remember trying them already.

@lili21
Copy link

lili21 commented Apr 28, 2017

I thought what you need is __webpack_public_path__ , why do you need publicPath ?

@silouanwright
Copy link
Author

I don't. I'm only using it because webpack_public_path isn't working

@lili21
Copy link

lili21 commented May 18, 2017

update to latest version . and It will work.

@novemberborn
Copy link

I think this is due to webpack/webpack#3265 (comment).

@michael-ciniawsky michael-ciniawsky removed their assignment Jul 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants