Webpack publicPath explained (such that I understand it)
I’ve been tripped up by WebPack’s publicPath config property so many times I’ve lost track. It’s one of those things that I don’t use every day, and I don’t know about you but if I don’t use something regularly I tend to forget it. That’s especially true if I don’t understand how or why this thing I need to understand came to be in the first place.
So I’ve had two new projects land in my lap in the last week. It’s resulted in my FINALLY understanding what this puppy does / how it works. Here (for my own future use) is what this thing does:
publicPath tells WebPack’s devServer the virtual folder locations of the output file(s) it generates. When you’re hot loading they only exist in memory, but index.html will of course be looking for them at some folder location. The publicPath property bridges the gap between index.html’s location and the generated file’s location.
Yep, it’s that simple. And it seems obvious in hindsight.