Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bundle.js file output and webpack-dev-server

Tags:

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 ?

like image 473
mguijarr Avatar asked Oct 24 '15 12:10

mguijarr


People also ask

How do I bundle a JavaScript file in webpack?

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.

Where does webpack-dev-server serve files from?

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.

What is the output of webpack?

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.

What is the use of webpack-dev-server?

webpack-dev-server can be used to quickly develop an application. See the development guide to get started.


1 Answers

[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

like image 131
chris Avatar answered Nov 10 '22 17:11

chris