jantimon/html-webpack-plugin

filename: "/index.html" doesn't work with webpack-dev-server

chulman444 opened this issue ยท 3 comments

Current behaviour ๐Ÿ’ฃ

Server run with webpack serve with new HtmlWebpackPlugin({ filename: "/index.html" }) results in 404 error.

Expected behaviour โ˜€๏ธ

I expect it to work like when I'm just building it with webpack or running the (express) server that uses webpack-dev-middleware.

Reproduction Example ๐Ÿ‘พ

https://codesandbox.io/s/html-webpack-plugin-5x-alpha-forked-iv9dn?file=/webpack.config.js

Environment ๐Ÿ–ฅ

>node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v14.16.0
win32 10.0.18363

>npm --version
6.14.11

>npm ls webpack
html-wepback-plugin-bug@1.0.0 D:\projects\test\webpack\html-wepback-plugin-bug
`-- webpack@5.46.0


>npm ls html-webpack-plugin
html-wepback-plugin-bug@1.0.0 D:\projects\test\webpack\html-wepback-plugin-bug
`-- html-webpack-plugin@5.3.2
N247S commented

I got the exact same issue. Sad this has been unattended for so long.

To shine a bit of light on this issue, The reason the browser cannot find the file is because the index.html file is actually not generated at the output directory (so defenitly a bug). as can be seen in the logs in the example provided by @chulman444 .

image

I assume it is defaulting to the project root, which is defenitly not correct. as the webpack output directory is set to path.resolve(__dirname, "app", "dist").

image

Sadly there is no workaround as far as I could find. For example you cannot set some sort of output directory in the constructor provided by the 'html-webpack-plugin' plugin.

Same problem here... Upvoting to fix this issue!

stale commented

This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.