perf(v2): significantly reduce bundle size & initial html payload (#1898)

* perf(v2): reduce bundle size significantly with super short chunk name and registry

* changelog

* use hash:8 as id for better long term caching

* even shorter filename. slice contenthash
This commit is contained in:
Endi 2019-10-27 21:09:19 +07:00 committed by Yangshun Tay
parent c23f981f67
commit fabaf7772b
7 changed files with 45 additions and 20 deletions

View file

@ -101,19 +101,27 @@ export function genChunkName(
modulePath: string,
prefix?: string,
preferredName?: string,
shortId?: boolean,
): string {
let chunkName: string | undefined = chunkNameCache.get(modulePath);
if (!chunkName) {
let str = modulePath;
if (preferredName) {
const shortHash = createHash('md5')
if (shortId) {
chunkName = createHash('md5')
.update(modulePath)
.digest('hex')
.substr(0, 3);
str = `${preferredName}${shortHash}`;
.substr(0, 8);
} else {
let str = modulePath;
if (preferredName) {
const shortHash = createHash('md5')
.update(modulePath)
.digest('hex')
.substr(0, 3);
str = `${preferredName}${shortHash}`;
}
const name = str === '/' ? 'index' : docuHash(str);
chunkName = prefix ? `${prefix}---${name}` : name;
}
const name = str === '/' ? 'index' : docuHash(str);
chunkName = prefix ? `${prefix}---${name}` : name;
chunkNameCache.set(modulePath, chunkName);
}
return chunkName;