I have the following webpack config:
module.exports = {
entry: "./src/index.js",
output: {
path: __dirname + '/dist',
// publicPath: __dirname + '/dist/',
filename: "bundle.js"
},
devServer: {
contentBase: "/dist",
hot: true,
}
}
My understanding is that contentBase
tells the webpack dev server where to serve files from. So if I go to localhost:8080/test.txt
, under this configuration the file at myProjectRoot/dist/test/txt
will be sent by the server to the browser. Is that correct? What does output.publicPath
have to do with all that?
Now I have index.html
and bundle.js
sitting in myProjectRoot/dist/
right now. (although I think bundle.js
is a bit of a confusing factor because its actually the in memory bundle that is returned by webpack-dev-server but nonetheless). Given my previous paragraph, I'd expect the server to return index.html
to the browser. Since the contentBase
is /dist
and index.html
's path on disk is ./dist/index.html
.
But instead I see: Cannot GET /
So again, if I go to http://localhost:8080/bundle.js
I see the full javascript bundle (up to date with what was last saved in my text editor). But then /index.html
wins up with Cannot GET /
?
What am I missing?