0
votes

When I used webpack-dev-server Webpack4 doesn't create folder 'dist' with file main.js.

My package.json

  {
  "name": "webpack-project",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "dev": "webpack-dev-server --mode development --open",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "path": "^0.12.7",
    "webpack": "^4.20.1",
    "webpack-cli": "^3.1.1",
    "webpack-dev-server": "^3.1.9"
  },
  "dependencies": {}
}

My webpack.config.js

const path = require('path');
module.export = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'main.js',
        publicPath: 'dist/'
    }
}

But if there is "dev": "webpack --mode production" in package.json file, folder 'dist' with main.js file create. Why it doesn't work when I use webpack-dev-server?

2

2 Answers

0
votes

webpac-dev-server uses webpack-dev-middleware and accordingly to its docs:

No files are written to disk, rather it handles files in memory

Files are served from memory, not from disk. That is why.

0
votes

You can use the writeToDisk option:

devServer: {
  devMiddleware: {
    writeToDisk: true,
  },
},