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

使用angular17时候发现报错chunk-xxx.js找不到。 #333

Open
punyfish opened this issue May 11, 2024 · 1 comment
Open

使用angular17时候发现报错chunk-xxx.js找不到。 #333

punyfish opened this issue May 11, 2024 · 1 comment

Comments

@punyfish
Copy link

punyfish commented May 11, 2024

膜拜大佬,求解惑。看了下面这段源码,发现把hash去掉了,导致chunk-xxx.js只会加载一个。这里冒昧的问下,为何要result[ext ? ${name}.${ext} : name] = assetsTag;。文件名相同hash后缀不同的不加载,这样会导致有些js不会加载
parseManifestFromHTML(html: string): Record<string, AssetsTagItem> { const result: Record<string, AssetsTagItem> = {}; const matchResult = html.match(STYLE_LINK_OR_SCRIPT_REG); matchResult.forEach(item => { const linkOrSrcResult = item.match(LINK_OR_SRC_REG); if (linkOrSrcResult && linkOrSrcResult[2]) { const src = linkOrSrcResult[2]; const hashName = getResourceFileName(src); let barSplitIndex = hashName.indexOf('-'); let dotSplitIndex = hashName.indexOf('.'); const splitIndex = barSplitIndex > -1 ? barSplitIndex : dotSplitIndex; if (splitIndex > -1) { const name = hashName.slice(0, splitIndex); const ext = getExtName(hashName); const assetsTag: AssetsTagItem = { src: src }; result[ext ?${name}.${ext}` : name] = assetsTag;

                const attributes = this.parseTagAttributes(item);
                if (attributes) {
                    assetsTag.attributes = attributes;
                }
                // const typeTagResult = item.match(TAG_TYPE_REG);
                // if (typeTagResult && typeTagResult[1]) {
                //     assetsTag.attributes = {
                //         type: typeTagResult[1]
                //     };
                // }
            }
        }
    });
    return result;
}`
@why520crazy
Copy link
Member

这里主要是由于加载哪些 scripts 是支持配置的,比如配置 ["main.js", "chunk.js"] 实际会通过这个名字找到对于的 hash 资源路径加载。

一般不会在 index.html 中输出多个 chunk-xxx.js 初始加载时一次性加载的,多个 chunk 都是延迟加载的,不知道你的具体场景是什么? 如果这个场景没有覆盖到,可以考虑如何支持一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants