The following are simple and simple rules for webpack and webpack-dev server:
- output.path . It must be an absolute path or
/ . You can easily get it using path.join - output.filename . This should be the name of the output file without any additional path to the file.
- devServer.contentBase . This is a physical disk location that serves as the root directory of the webpack-dev server when opening
http://localhost:8080
By convention, we save both output.path and devServer.contentBase . The tricky part is when you start webpack cmd, it creates a physical bundle.js file.
But when you start webpack-dev-server , NO PHYSICAL OUTPUT is generated, but it stores the generated output in memory to avoid working with the file, which in turn helps to speed up the development / debugging cycle.
Thus, any change you make in the src.js or main.js file will generate a result, but will not write it to disk, and wepack-dev-server reads it directly from memory.
- output.publicPath . This is used by webpack, webpack-dev-server and another plugin to generate output or service the generated package. The default value is
/ .
This is a VIRTUAL PATH and does not need to be present on the physical disk. Example: final application name if several applications are located on the same server as /app1 , /app2 or some external CDN /CDN-Path .
It is also useful for React-Router <BrowserRouter basename='/app1'>
Now, in order to transfer the output file of the package that is generated and stored in memory, you need to add output.publicPath ie Virtual Path to the browser URL.
The final URL for the webpack-dev server will be: http://localhost:8080/<output.publicPath>/<output.filename>
In your case, either you change publicPath: path.join(__dirname, 'dist') to publicPath: '/dist' if it contains any spaces. You can verify it by typing path.join(__dirname, 'dist') , which returns the release path [different on MacOS and Window].
http://localhost:8080/dist/bundle.js
If you want to dig deeper, here is the URL
https://medium.com/p/webpack-understanding-the-publicpath-mystery-aeb96d9effb1