Webpack 4. 使用 webpack-dev-server 时不将文件复制到实际输出文件夹

Webpack 4. Does not copy files to actual output folder when webpack-dev-server is used

当我使用 webpack-dev-server Webpack4 没有创建文件夹 'dist' 和文件 main.js

我的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": {}
}

我的webpack.config.js

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

但是如果package.json文件中有"dev": "webpack --mode production",文件夹'dist'和main.js 文件创建。 为什么当我使用 webpack-dev-server?

时它不起作用

webpack-dev-server 使用 webpack-dev-middleware 并根据其文档:

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

文件是从内存中提供的,而不是从磁盘中提供的。这就是为什么。