使用 writeToDisk 时 Webpack 无效的选项对象

Webpack invalid options object when using writeToDisk

我正在尝试将 webpack 用于我的 Web 开发项目,但不知道如何使用 writeToDisk 选项。

这是我的 webpack.config.development.js 文件:

const { merge } = require('webpack-merge')
const path = require('path')

const config = require('./webpack.config')

module.exports = merge(config, {
  mode: 'development',

  devtool: 'inline-source-map',

  devServer: {
    writeToDisk: true
  },

  output: {
    path: path.resolve(__dirname, 'public')
  }
})

而我运行npm start的结果如下:

C:\Users\natha\OneDrive\Documents\web\floema>npm start

> floema@1.0.0 start
> npm run development


> floema@1.0.0 development
> webpack serve --progress --config webpack.config.development.js

C:\Users\natha\OneDrive\Documents\web\floema\app C:\Users\natha\OneDrive\Documents\web\floema\assets C:\Users\natha\OneDrive\Documents\web\floema\styles
1% setup initialize[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'writeToDisk'. These properties are valid:
   object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }

谢谢!

https://github.com/webpack/webpack-dev-server/blob/master/migration-v4.md and https://github.com/webpack/webpack-dev-server/issues/3768 中所述,选项 writeToDisk 已移至 devServer.devMiddleware,因此现在需要这样配置:

module.exports = {
  devServer: {
    devMiddleware: {
      writeToDisk: true,
    },
  },
};