How to use __webpack_public_path__ variable in a Webpack configuration? How to use __webpack_public_path__ variable in a Webpack configuration? reactjs reactjs

How to use __webpack_public_path__ variable in a Webpack configuration?


Here's my basic setup in terms of the generated HTML:

<script>    window.resourceBaseUrl = 'server-generated-path';</script><script src="path-to-bundle" charset="utf-8"></script>

My main entry point script:

__webpack_public_path__ = window.resourceBaseUrl;


Not a big webpack expert, but I'm not sure you are using that loader in the right way. The url-loader is there to help you load files data that are required/imported in your code.

So if in your entry point you write something like:

var imageData = require("path/to/my/file/file.png");

Webpack will see that you are trying to import something different than a .js file and then will search in your configured loader list, to see if it can use any loader to load that resource.

Since you had set up a loader whith a test property that matches your required resource type (extension .png), it will use that configured loader (url-loader) to try loading that resource into your bundle.

You can also tell webpack what loader he needs to use by prepending the loader (and some query strings if you wish) in the require path:

var imageData = require("url-loader?mimetype=image/png!path/to/my/file/file.png");

Also, I'm not sure there is even a name parameter you can pass to the url-loader.