使用writeToDisk时Webpack无效选项对象

vd2z7a6w  于 2023-04-21  发布在  Webpack
关注(0)|答案(2)|浏览(259)

我尝试在我的web开发项目中使用webpack,但不知道如何使用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? }

谢谢!

sy5wg1nm

sy5wg1nm1#

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

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

yyyllmsg2#

在webpack.config.development.js页面

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

相关问题