3

I'm new to webpack and I'm using webpack dev server for HOT reload.My config looks like this:

new WebpackDevServer(webpack(config), {
    publicPath: "./public/dist/bundle.js",
    hot: true,
    historyApiFallback: true,
    proxy: {
        '*': {
            target: 'http://localhost:3000',
            secure: false
        }
    }
}).listen(8080, 'localhost', function (err, result) {
    if (err) {
        return console.log(err);
    }

    console.log('Listening at http://localhost:8080/');
});

and when I start the webpack dev server, I expect it to bundle the js at ./public/dist/bundle.js as specified. But it doesn't do. However it prints like as if it have done the bundle processing:

Version: webpack 1.13.1
Time: 93044ms
                  Asset    Size  Chunks             Chunk Names
./public/dist/bundle.js  999 kB       0  [emitted]  main

But in my file system bundle.js is not present.

I could able to make it work by running webpack first and then calling webpack dev server, which is working as expected!

Where I'm making mistake?

Ant's
  • 13,545
  • 27
  • 98
  • 148
  • Do you use correct webpack.config.js ? Copy from question https://stackoverflow.com/questions/43206062/why-do-i-have-to-put-babel-presets-inside-babelrc-and-webpack-config-js – zloctb Jan 09 '19 at 08:09

2 Answers2

6

Note that webpack-dev-server runs in-memory so it won't generate any files you should see by definition. If you want actual files, you should use webpack --watch. You can run webpack --watch and webpack-dev-server in parallel if you want to get both files and HMR.

Juho Vepsäläinen
  • 26,573
  • 12
  • 79
  • 105
  • So by no ways we can write the in memory bundle to a file? – Ant's Jul 17 '16 at 15:04
  • 1
    That kind of goes against the idea of webpack-dev-server since it needs to be as fast as possible. If you want actual files, then running `webpack --watch` next to it does the trick. Examine the dev server source for the exact idea of how it does its magic. – Juho Vepsäläinen Jul 17 '16 at 15:50
3

It is in-memory, but you can set it to also write the bundles (WebPack v4) with:

"writeToDisk: true
James Joyce
  • 1,694
  • 18
  • 20