mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +02:00
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:
parent
c23f981f67
commit
fabaf7772b
7 changed files with 45 additions and 20 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue