From dad21501467351e96db9c0bd670206826a0eaeee Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 4 Oct 2022 07:00:10 +0200 Subject: [PATCH] Add documentation --- docs/999-big-list-of-options.md | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/999-big-list-of-options.md b/docs/999-big-list-of-options.md index 202ffa95918..7ecf986f2da 100755 --- a/docs/999-big-list-of-options.md +++ b/docs/999-big-list-of-options.md @@ -466,6 +466,52 @@ Type: `boolean`
CLI: `--compact`/`--no-compact`
Default: `false` This will minify the wrapper code generated by rollup. Note that this does not affect code written by the user. This option is useful when bundling pre-minified code. +#### output.dynamicImportInCjs + +Type: `boolean`
CLI: `--dynamicImportInCjs`/`--no-dynamicImportInCjs`
Default: `true` + +While CommonJS output originally supported only `require(…)` to import dependencies, recent Node versions also started to support `import(…)`, which is the only way to import ES modules from CommonJS files. If this option is `true`, which is the default, Rollup will keep external dynamic imports as `import(…)` expressions in CommonJS output. Set this to `false` to rewrite dynamic imports using `require(…)` syntax. + +```js +// input +import('external').then(console.log); + +// cjs output with dynamicImportInCjs: true or not set +import('external').then(console.log); + +// cjs output with dynamicImportInCjs: false +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty( + n, + k, + d.get + ? d + : { + enumerable: true, + get: function () { + return e[k]; + } + } + ); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +Promise.resolve() + .then(function () { + return /*#__PURE__*/ _interopNamespaceDefault(require('external')); + }) + .then(console.log); +``` + #### output.entryFileNames Type: `string | ((chunkInfo: ChunkInfo) => string)`
CLI: `--entryFileNames `
Default: `"[name].js"`