Skip to content

Commit

Permalink
perf(v2): improve dev build time by not overwriting file if possible (#…
Browse files Browse the repository at this point in the history
…2089)

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

* minor improvement

* docs
  • Loading branch information
endiliey authored Dec 6, 2019
1 parent ff48519 commit 32c9d07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions website/docs/markdown-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 32c9d07

Please sign in to comment.