使用React.lazy进行代码拆分后添加捆绑包的推荐方法

时间:2020-02-01 21:31:35

标签: reactjs bundle webpack-4

我已经使用React.lazy作为documented here.用Webpack拆分了我的React代码 分割后,我有几个文件,如预期的那样。

1.bundle.js
2.bundle.js
3.bundle.js
main.bundle.js

我注意到,如果我没有在ChunkLoadError: Loading chunk 0 failed中包括所有捆绑包,则应用程序将引发错误index.html。这是预期的行为吗?

<html>
<body style="overflow: hidden">
    <div id="app"></div>
    <script src="/dist/main.bundle.js"></script>
    <script src="/dist/0.bundle.js"></script>
    <script src="/dist/1.bundle.js"></script>
    <script src="/dist/2.bundle.js"></script>
    <script src="/dist/3.bundle.js"></script>
    <script src="/dist/4.bundle.js"></script>
    <script src="/dist/5.bundle.js"></script>
    <script src="/dist/6.bundle.js"></script>
    <script src="/dist/7.bundle.js"></script>
    <noscript>
        Sorry, this page requires javascript!
     </noscript>
</body>
</html>

是否有推荐的方法可以自动添加这些捆绑包,而不必手动添加它们?

非常感谢/ K

0 个答案:

没有答案
相关问题