perf(v2): improve dev build time by not overwriting file if possible (#2089)

* perf(v2): improve sequential build time by not overwriting file if possible

* minor improvement

* docs
This commit is contained in:
Endi 2019-12-06 12:17:41 +07:00 committed by GitHub
parent ff4851982c
commit 32c9d07b90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -27,7 +27,19 @@ export async function generate(
return;
}
const lastHash = fileHash.get(filepath);
let lastHash = fileHash.get(filepath);
// If file already exist but its not in runtime cache hash yet,
// we try to calculate the content hash and then compare
// This is to avoid unnecessary overwrite and we can reuse old file
if (!lastHash && fs.existsSync(filepath)) {
const lastContent = await fs.readFile(filepath, 'utf8');
lastHash = createHash('md5')
.update(lastContent)
.digest('hex');
fileHash.set(filepath, lastHash);
}
const currentHash = createHash('md5')
.update(content)
.digest('hex');

View file

@ -183,6 +183,7 @@ For example, if you are in `doc2.md` and you want to reference `doc1.md` and `fo
```md
I am referencing a [document](doc1.md). Reference to another [document in a folder](folder/doc3.md)
[Relative document](../doc2.md) referencing works as well.
```
One benefit of this approach is that the links to external files will still work if you are viewing the file on GitHub.