webpack dev server is not creating the bundle file

旧时模样 提交于 2021-02-07 09:42:27

问题


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?


回答1:


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.




回答2:


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

"writeToDisk: true


来源:https://stackoverflow.com/questions/38418372/webpack-dev-server-is-not-creating-the-bundle-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!