Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Feature Request: Make bundling and rules 2 different concepts #6944

Open
vicb opened this issue Oct 10, 2024 · 1 comment
Open

🚀 Feature Request: Make bundling and rules 2 different concepts #6944

vicb opened this issue Oct 10, 2024 · 1 comment
Labels
discussion This issue is being used to discuss a topic rather than track a feature or bug. enhancement New feature or request

Comments

@vicb
Copy link
Contributor

vicb commented Oct 10, 2024

  1. We have rules to upload different files:
rules = [
  { type = "CommonJS", globs = ["**/*.js"], fallthrough = true }
]
  1. By default wrangler bundles all the files together (using esbuild) that is rules from 1 above are ignore and all the imports are inlined.

As of today 1 and 2 are grouped around a single "Bundling" paradigm.

That is:

  • wrangler deploys will activate 2 and ignore 1
  • wrangler deploys --no-bundle will activate 1 and skip 1 (esbuild)

I believe 1 and 2 should be different concepts and not mutually exclusive.

For example you could have you framework composed of multiple files and then a directory containing the different pages of your application.

- app/
  - index.js
  - util.js
  - render.js
- pages/
  - homepage.js  
  - about.js

In that case it would be nice to bundle the app into a single file (2) and being able to require the page matching the url (1).

Updating ESBuild could solve some of the use case with wildcard imports.

workerd recently introduced createRequire. You can now write:

import { createRequire } from 'module';
const require = createRequire('/');
const msg = require('./hello.cjs').world();
console.log(`hello ${msg}`);

The code works fine with --no-bundle - as long as the hello.cjs has a matching rule in wrangler.toml.
However the code will fail without --no-bundle because it can not resolve hello.cjs.
If require is passed a variable, the code will fail to build because of the dynamic require.

That's why I believe we should be able to bundle the app/framework but still have module that you can require.

If both 1 and 2 can be used together, files matched by a rules must be marked as external so that esbuild does not try to inline them.

/cc @IgorMinar

@vicb vicb added enhancement New feature or request discussion This issue is being used to discuss a topic rather than track a feature or bug. labels Oct 10, 2024
@threepointone
Copy link
Contributor

Can you explain the usecase you're going for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This issue is being used to discuss a topic rather than track a feature or bug. enhancement New feature or request
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants