15

I have the following webpack config:

var path = require('path')
var webpack = require('webpack')


module.exports = {
   entry: {
      main: './scripts/app/main.js'
   },
  output: {
     path: path.resolve(__dirname, './scripts/app/bundle/'),
     publicPath: '/scripts/app/bundle/',
     filename: '[name].js'
  },
  ...

When i run the command npm run dev it shows that main.js has been emitted

When I browse to /scripts/app/bundle/main.js sure enough the file is loaded in the browser

But when i look inthe physical path there is no file - seems like its only in memory

This is what I have in package.json:

"scripts": {
  "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
  "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
 },

How do I generate a physical file.

adam78
  • 9,668
  • 24
  • 96
  • 207

2 Answers2

24

webpack-dev-server does not generate files on disk -- only on memory. However you do have some options:

  • Option 1: Stop the dev server and instead run the command webpack --watch, which will use webpack to build your app and produce output to the disk. The downside is you won't have hot reloading.
  • Option 2: Append /webpack-dev-server to the URL where you are running the server. So, if your server is running on localhost:3000, you can view files by going to the URL http://localhost:3000/webpack-dev-server. The files will still be served from memory, but you will be able to see them through this URL.
  • Option 3: See this plugin. It will force webpack-dev-server to write files to disk.
Christian Santos
  • 5,386
  • 1
  • 18
  • 24
  • 4
    Update: there is not a `writeToDisk` [option](https://webpack.js.org/configuration/dev-server/#devserverwritetodisk-) – ChristianMurschall Mar 21 '19 at 09:10
  • @ChristianMurschall there is a `writeToDisk` option, but was moved into `devMiddleware` https://webpack.js.org/configuration/dev-server/#devserverdevmiddleware – WW00WW May 01 '22 at 14:21
0

webpack-dev-server supports writing output to disk, use writeToDisk option under devMiddleware option

References:

WW00WW
  • 417
  • 4
  • 15