Is it possible to have `publicPath` configured dynamically in the browser with webpack?

Okay so I was looking for this all day and then found it just after deciding to post here!

Just in case anyone else needs this:

The solution is to define __webpack_public_path__ at runtime when making a production build. But be careful not to use it in development as it can mess up module hot-loading.

More info here:

http://webpack.github.io/docs/configuration.html#output-publicpath