Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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