Wrangler: Support of dynamic import

Created on 13 Feb 2020  路  4Comments  路  Source: cloudflare/wrangler

馃挕 Feature request

Overview and problem statement

Dynamic import is a way of dynamicly importing a JavaScript file, it's a JavaScript function.

Using webpack we will currently emit code that won't run, as shown by https://github.com/cloudflare/wrangler/issues/1044.

I don't know if we want to support loading file "dynamically" in Cloudflare workers. But if we do we should:

  1. limit to statically known values (import(lol() + ".js") would be disallowed )
  2. manually bundle files that matches the url
  3. transpile the function call to wire up to the content

It's worth notting that it works with WebAssembly Modules because they are handled differently and we transpile the import function to an identifier (which maps to the worker binding).

Basic example

await import("something.js")
category - feature status - needs design

Most helpful comment

@xtuc @EverlastingBugstopper is there any conclusion on whether this will be implemented or not? If so, is there any ETA?

The current 1MB script limit makes it impossible to publish any large React app with Cloudflare Workers since Wrangler compiles everything to a single file, you easily end up with 5MB+ files. If dynamic imports were available, then developers could make use of React.lazy to handle lazily importing components via dynamic import.

All 4 comments

I see no reason not to support this if it's something the runtime will accept. In my opinion, we should make Wrangler as straightforward to use for simple cases, and make it flexible enough for superusers. If someone can do something through the API and their own build tools, I see no reason not to support in Wrangler.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because it has not had recent activity. You may re-open the issue if it is still relevant.

@xtuc @EverlastingBugstopper is there any conclusion on whether this will be implemented or not? If so, is there any ETA?

The current 1MB script limit makes it impossible to publish any large React app with Cloudflare Workers since Wrangler compiles everything to a single file, you easily end up with 5MB+ files. If dynamic imports were available, then developers could make use of React.lazy to handle lazily importing components via dynamic import.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickbalestra picture nickbalestra  路  5Comments

jahredhope picture jahredhope  路  4Comments

simplenotezy picture simplenotezy  路  5Comments

steveklabnik picture steveklabnik  路  7Comments

PierBover picture PierBover  路  5Comments