Reputation: 7900
I have this output configuration in my webpack.config file:
config = {
...
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: 'http://localhost:8090/'
},
... }
The bundle.js is not written to the path specified in path
; it is only available through the
web server whereas I would like both.
What should I change to have both the file and the web server ?
Upvotes: 28
Views: 17716
Reputation: 3321
[Original]
It appears this is now a built-in option. You can add the following in your webpack config file.
devServer: {
writeToDisk: true
}
Looks like this was added as of webpack-dev-server version 3.1.10
[2021-11-09] Webpack 5 The syntax appears to have changed in Webpack 5 (you now pass a config option to the specific middleware that handles the assets):
module.exports = {
devServer: {
devMiddleware: {
writeToDisk: true,
},
},
};
Webpack v4 docs: https://v4.webpack.js.org/configuration/dev-server/#devserverwritetodisk- Webpack v5 docs: https://webpack.js.org/configuration/dev-server/#devserverdevmiddleware
Upvotes: 68
Reputation: 1402
This plugin will force webpack-dev-server
to also write bundle files, eliminating the need to run two processes in terminal.
gajus/write-file-webpack-plugin
Upvotes: 2
Reputation: 53681
When you run webpack-dev-server you are not actually bundling and rebuilding the webpack bundle, it is only serving it from memory.
In my experience, the way around this is to have two instances running if you wand to have the actual build as well as the webpack-dev-server. So, in one terminal window have
webpack --watch
running, ( webpack --watch will rebuild the actual bundle ). Then, in another terminal have
webpack-dev-server
running, ( webpack-dev-server will live reaload and serve from memory the new build ).
Upvotes: 29