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
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ 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');
}

const currentHash = createHash('md5')
.update(content)
.digest('hex');
Expand Down