perf(v2): skip runtime fileHash cache in prod & get timestamp asynchronously (#1951)

* skip hash calculation in prod when generating file

* perf: convert lastUpdated to be async process

* changelog
This commit is contained in:
Endi 2019-11-08 23:35:39 +07:00 committed by GitHub
parent e04c8f140f
commit 639d8d3eac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 42 deletions

View file

@ -17,8 +17,16 @@ export async function generate(
generatedFilesDir: string,
file: string,
content: any,
skipCache: boolean = process.env.NODE_ENV === 'production',
): Promise<void> {
const filepath = path.join(generatedFilesDir, file);
if (skipCache) {
await fs.ensureDir(path.dirname(filepath));
await fs.writeFile(filepath, content);
return;
}
const lastHash = fileHash.get(filepath);
const currentHash = createHash('md5')
.update(content)
@ -110,7 +118,7 @@ export function genChunkName(
modulePath: string,
prefix?: string,
preferredName?: string,
shortId?: boolean,
shortId: boolean = process.env.NODE_ENV === 'production',
): string {
let chunkName: string | undefined = chunkNameCache.get(modulePath);
if (!chunkName) {