A question about webpack require

for the following code, after testing, you can observe:

  1. uses the @ root/test/test.js of the string, and the module can load on demand, loading the routing-related file
  2. only when the test/test route is triggered.
  3. uses the variable @ root/$ {route} .js , but the modules are packaged together, and the relevant packages are loaded before the route is triggered

what is the cause of this problem? What should I do if I need to achieve on-demand loading? It feels cumbersome to write each route once.
clipboard.png


this should be a normal phenomenon. Webpack is a static baler, and all modules should be statically parsed, so when it encounters require ('xxxx'), it will parse which modules are contained in the string, so it is natural that all cases corresponding to route will be typed into the same package.

There is also a solution to

, which I have encountered before, using the loader of bundle-loader . The method of use is something like this:

require('bundle!./foo/bar/' + dynamicSegment);
As for the general principle of

, because we don't bother with webpack much now, we all use things like cli, and I can't remember clearly, but you can take a look at this issue , which should be similar issues discussed.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54ade-452ae.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54ade-452ae.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?