worktile / ngx-planet

🚀🌍🚀A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.
http://planet.ngnice.com
MIT License
536 stars 67 forks source link

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

Open punyfish opened 3 months ago

punyfish commented 3 months ago

膜拜大佬,求解惑。看了下面这段源码,发现把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 commented 3 months ago

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

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

punyfish commented 2 months ago

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

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

angular17采用@angular-builders/custom-esbuild:application进行打包时候发现:index.html中会加载多个chunk-xxx.js。新项目从qiankun改为拥抱ngx-planet了!