0

I have the following problem, when I use webpack in watchmode and write the results to a file webpack is not replacing the old data instead it append the new. When I run a build everything works fine the old data get replaced with the new one.

Is there a way that the watchmode also overrides the data instead of appending it?

These are the parameters which I use

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

The offical documentation dont give a hint here

Stats Data Documentation

For example the file stats.json is empty. So I run the command appove and following content is write to the file.

{
  "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
  ]
}

So now something change in my files and the watcher detected this and rerun. So he do the output again to the file. But it only append it so its look like this

{
  "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
  ]
}

But I want that its replace the old data so there is still only one result in the file.

Darem
  • 1,689
  • 1
  • 17
  • 37
  • [Use `>>` instead of `>`](https://stackoverflow.com/questions/17701989/how-do-i-append-text-to-a-file) ? Not sure what data are you talking about. – Mike Doe Jan 08 '19 at 07:27

1 Answers1

0

> overwrites file contents in Linux. Use the >> append operator instead:

webpack --env development --watch --json >> stats.json
Mike Doe
  • 16,349
  • 11
  • 65
  • 88
  • I´m sorry too early to rejoice it only works when running the watch command the first time. But when some changes in file happen and the watcher rerun it still append and do not replace the content. – Darem Jan 08 '19 at 07:43
  • I'm afraid I don't follow. Can you explain what are you trying to achieve? Maybe with some examples. – Mike Doe Jan 08 '19 at 07:45