Nikita Shchypyplov
Nikita Shchypyplov

Reputation: 1160

How does Webpack dev server consume bundle without file in build directory?

I have noticed, that when I run webpack I have all my bundled files in build directory, but when I run webpack-dev-server I don't see them in build directory, nevertheless all is running.

How does WDS manage to do that? There are my scripts:

  "scripts": {
    "build": "npx yarn clean && webpack --mode production",
    "buildRemote": "npx yarn clean && webpack --config webpack.config.remote.js",
    "clean": "rm -rf build",
    "watch": "webpack-dev-server --quite --no-info"
  },

Thanks!

Upvotes: 0

Views: 486

Answers (1)

Alex Michailidis
Alex Michailidis

Reputation: 4143

The difference here is how each method treats webpack's generated assets.

When you run the webpack command everything is going to the declared output.path via the fs module. In other words, generated assets are written to disk.

Now when you run webpack-dev-server, under the hood webpack-dev-middleware kicks in. This is an express middleware that serves webpack's generated assets. Under the hood, it uses memory-fs and as the name suggests this is a file system module that handles everything in javascript objects that being held in memory.

Upvotes: 3

Related Questions