Given this config:
var webpack = require(\'webpack\');
const path = require(\'path\')
module.exports = {
entry: \"./src/index.js\",
output: {
path:
Below are simple and straight forward rules for webpack & webpack-dev-server :
/
. You can get it easily using path.join
http://localhost:8080
By convention, we keep both output.path
and devServer.contentBase
same.
The tricky part is when you run webpack
cmd, it generates the physical bundle.js
file.
But when you run webpack-dev-server
, NO PHYSICAL OUTPUT file is generated, rather it keeps the generated output in memory to avoid File-Write operate which in turn helps in faster development/debugging cycle.
So any change you make in src.js or main.js
file, it will generate the output but won't write that to disk and wepack-dev-server reads that directly from the memory.
/
. It is VIRTUAL PATH and need not be present on the physical disk. Example : final application name if multiple apps are hosted on the same server like
/app1
,/app2
, or some external CDN path/CDN-Path
.It is also helpful for React-Router
Now to refer the bundle output file that is generated & kept in the memory , you need to append the output.publicPath
i.e. Virtual Path
in the browser's URL.
The final URL for webpack-dev-server will be :
http://localhost:8080/
In your case, either you change the
publicPath: path.join(__dirname, 'dist')
to
publicPath: '/dist'
if it contains any spaces.
You can check it by printing the value of path.join(__dirname, 'dist')
which returns the absolve path [different on MacOS & Window system].
http://localhost:8080/dist/bundle.js
If you want to dig further deeper, then here is the URL
https://medium.com/p/webpack-understanding-the-publicpath-mystery-aeb96d9effb1