search

Home  >  Q&A  >  body text

javascript - webpack packaging, dependency loading

Ask the master, webpack usually outputs a complete js file. How can the generated js module be loaded dependently?

PHP中文网PHP中文网2805 days ago555

reply all(4)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:28:12

    Entry sets multiple entry files and packages them into multiple
    require.ensure to separate modules that need to be loaded asynchronously on demand

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:28:12

    If you’re not sure if you understand it correctly, you can refer to it.
    First of all, webpack packaging can package js into independent files, so who is still not together.
    Secondly, load some js modules by using asynchronous loading in main.js.
    At this time, you will usually get two or more js files after packaging. One is required for the homepage, and the other js is loaded when it is loaded into the corresponding module or page.
    Hope this helps

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:28:12

    • If you use the latest Webpack2, the specification document recommends using import 替换过时的 require.ensure.

    • Officially also recommended to usebundle-loader

    I didn’t test the first one successfully, but the second one works.

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:28:12

    There are multiple entrances in the entry, I will show you the screenshot and you will understand

    reply
    0
  • Cancelreply