【问题标题】:Webpack override stats data in watch modeWebpack 在 watch 模式下覆盖 stats 数据
【发布时间】:2019-06-02 20:42:24
【问题描述】:

我有以下问题,当我在监视模式下使用 webpack 并将结果写入文件时,webpack 不会替换旧数据,而是附加新数据。当我运行构建时,一切正常,旧数据被新数据替换。

有没有办法让监视模式也覆盖数据而不是附加数据?

这些是我使用的参数

webpack --env development --watch --json > stats.json

官方文档在这里没有给出提示

Stats Data Documentation

例如文件 stats.json 是空的。所以我运行命令 appove 并将以下内容写入文件。

{
  "version": "1.4.13", // Version of webpack used for the compilation
  "hash": "11593e3b3ac85436984a", // Compilation specific hash
  "time": 2469, // Compilation time in milliseconds
  "filteredModules": 0, // A count of excluded modules when `exclude` is passed to the `toJson` method
  "outputPath": "/", // path to webpack output directory
  "assetsByChunkName": {
    // Chunk name to emitted asset(s) mapping
    "main": "web.js?h=11593e3b3ac85436984a",
    "named-chunk": "named-chunk.web.js",
    "other-chunk": [
      "other-chunk.js",
      "other-chunk.css"
    ]
  },
  "assets": [
    // A list of asset objects
  ],
  "chunks": [
    // A list of chunk objects
  ],
  "modules": [
    // A list of module objects
  ],
  "errors": [
    // A list of error strings
  ],
  "warnings": [
    // A list of warning strings
  ]
}

所以现在我的文件发生了一些变化,观察者检测到了这一点并重新运行。所以他再次对文件进行输出。但它只是附加它,所以它看起来像这样

{
  "version": "1.4.13", // Version of webpack used for the compilation
  "hash": "11593e3b3ac85436984a", // Compilation specific hash
  "time": 2469, // Compilation time in milliseconds
  "filteredModules": 0, // A count of excluded modules when `exclude` is passed to the `toJson` method
  "outputPath": "/", // path to webpack output directory
  "assetsByChunkName": {
    // Chunk name to emitted asset(s) mapping
    "main": "web.js?h=11593e3b3ac85436984a",
    "named-chunk": "named-chunk.web.js",
    "other-chunk": [
      "other-chunk.js",
      "other-chunk.css"
    ]
  },
  "assets": [
    // A list of asset objects
  ],
  "chunks": [
    // A list of chunk objects
  ],
  "modules": [
    // A list of module objects
  ],
  "errors": [
    // A list of error strings
  ],
  "warnings": [
    // A list of warning strings
  ]
}{
  "version": "1.4.13", // Version of webpack used for the compilation
  "hash": "11593e3b3ac85436984a", // Compilation specific hash
  "time": 2469, // Compilation time in milliseconds
  "filteredModules": 0, // A count of excluded modules when `exclude` is passed to the `toJson` method
  "outputPath": "/", // path to webpack output directory
  "assetsByChunkName": {
    // Chunk name to emitted asset(s) mapping
    "main": "web.js?h=11593e3b3ac85436984a",
    "named-chunk": "named-chunk.web.js",
    "other-chunk": [
      "other-chunk.js",
      "other-chunk.css"
    ]
  },
  "assets": [
    // A list of asset objects
  ],
  "chunks": [
    // A list of chunk objects
  ],
  "modules": [
    // A list of module objects
  ],
  "errors": [
    // A list of error strings
  ],
  "warnings": [
    // A list of warning strings
  ]
}

但我希望它替换旧数据,因此文件中仍然只有一个结果。

【问题讨论】:

标签: webpack webpack-4


【解决方案1】:

> 覆盖 Linux 中的文件内容。请改用 >> 附加运算符:

webpack --env development --watch --json >> stats.json

【讨论】:

  • 我很抱歉为时过早庆幸它仅在第一次运行 watch 命令时才有效。但是当文件发生一些变化并且观察者重新运行时,它仍然追加并且不替换内容。
  • 恐怕我没跟上。你能解释一下你想达到什么目标吗?也许有一些例子。
猜你喜欢
  • 2019-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-12-18
  • 2020-11-30
  • 2022-10-05
  • 2016-09-08
  • 1970-01-01
  • 2013-11-23
相关资源
最近更新 更多