GoogleChromeLabs / tooling.report

tooling.report a quick way to determine the best build tool for your next web project, or if tooling migration is worth it, or how to adopt a tool's best practice into your existing configuration and code base.
https://tooling.report
Apache License 2.0
847 stars 49 forks source link

Add dynamic require tests #420

Open aminya opened 3 years ago

aminya commented 3 years ago

The CJS tests are requiring modules at the top level which is different from dynamic requires. The tests should also cover dynamic requires.

https://github.com/GoogleChromeLabs/tooling.report/blob/dev/tests/importing-modules/subtests/commonjs/rollup/src/index.js

const cjs = require('./cjs');
console.log(cjs);

The proposed test for dynamic requires:

function main() {
  const cjs = require('./cjs');
  console.log(cjs);
}

The tool should code-split the lazy-loaded module similar to dynamic imports.

Dynamic requires are very important because the new ECMascript standard doesn't provide any way to synchronously lazy load a module.