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 ?
You can bundle your JavaScript using the CLI command by providing an entry file and output path. Webpack will automatically resolve all dependencies from import and require and bundle them into a single output together with your app's script.
The webpack-dev-server will serve the files in the current directory, unless you configure a specific content base. Using this config webpack-dev-server will serve the static files in your public folder. It'll watch your source files for changes and when changes are made the bundle will be recompiled.
Configuring the output configuration options tells webpack how to write the compiled files to disk. Note that, while there can be multiple entry points, only one output configuration is specified.
webpack-dev-server can be used to quickly develop an application. See the development guide to get started.
[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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With