Skip to content

writeConfig: Support inlineDynamicImports: trueΒ #208

@grekko

Description

@grekko

πŸ‘‹πŸ½ Hi!

I'd like to consume a module – specifically @hotwired/turbo-rails – which dynamically imports another module (see https://github.com/hotwired/turbo-rails/blob/acbb9250cf97cbf9f00570cbfbdeeffc815003b8/app/javascript/turbo/cable.js#L11-L14).

rollup seems to automatically enable code splitting for the bundle, which causes faucet-pipeline-js to complain (see

if(output.length !== 1) { // just to be safe
throw new Error("unexpected chunking");
}
).


I could work around the issue by patching lib/bundle/bundler.js to inline the dynamic import:

diff --git a/lib/bundle/bundler.js b/lib/bundle/bundler.js
index f0fb301..3f2ffe1 100644
--- a/lib/bundle/bundler.js
+++ b/lib/bundle/bundler.js
@@ -11,6 +11,7 @@ module.exports = function generateBundle(entryPoint, config, cache) {
 	return rollup.rollup(options).
 		then(bundle => {
 			cache = bundle;
+			writeConfig.inlineDynamicImports = true;
 			return bundle.generate(writeConfig);
 		}).
 		then(({ output }) => {

… and now I got some questions and hope you can help me understanding the situation.


I understand that rollup does this automatic code splitting when detecting dynamic imports for some optimization (or whatever good reason they have :)).

I also understand that faucet-pipeline-js currently does not support a chunked result from rollup.

Given that these statements are correct, I understand that one could configure rollup to disable the dynamic import optimization but inlining the import, which would resolve my issue.

If this sounds reasonable: Would you be open for a PR that would allow passing such a configuration option directly to rollup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions