Html-webpack-plugin: Why default behavior of generating asset path is not started with root path?

Created on 23 Jan 2017  路  3Comments  路  Source: jantimon/html-webpack-plugin

I just had an issue with pathnames with multiple slashes(/.../).

With default behavior, it generates following scripts:
<script type="text/javascript" src="bundle.js"></script>

In SPA, If we navigate to URL like http://somehost/path1/path2, it try to load assets from http://somehost/path1/bundle.js, not http://somehost/bundle.js so it failed to initialize the application.

I found that we can override the path via setting publicPath to '/' so that every assets can be loaded from root path, but the default publicPath value was ''.

Is there any reason that default behavior is not generated with '/'?

Most helpful comment

Default publicPath goes from your webpack config output.publicPath, which maybe set or maybe not. If you ask why webpack doesn't have output.publicPath set to / by default then it would be better to ask that question in webpack's repo.

If you ask why html-webpack-plugin doesn't have it set to / by default when publicPath is missing, then it's simple (I assume why it's so here): because having it as output.publicPath is a good default. After all, you don't want to have troubles with someone intentionally net setting output.publicPath but suddenly having publicPath as / in html-webpack-plugin.

All 3 comments

Default publicPath goes from your webpack config output.publicPath, which maybe set or maybe not. If you ask why webpack doesn't have output.publicPath set to / by default then it would be better to ask that question in webpack's repo.

If you ask why html-webpack-plugin doesn't have it set to / by default when publicPath is missing, then it's simple (I assume why it's so here): because having it as output.publicPath is a good default. After all, you don't want to have troubles with someone intentionally net setting output.publicPath but suddenly having publicPath as / in html-webpack-plugin.

Correct :)
It would not allow to have relative paths

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

var-bp picture var-bp  路  3Comments

klinki picture klinki  路  3Comments

lonelyclick picture lonelyclick  路  3Comments

meleyal picture meleyal  路  3Comments

amorphius picture amorphius  路  3Comments