Skip to content

[APPS] Use manualChunks for self-contained backend function builds#317

Merged
yoannmoinet merged 1 commit intomasterfrom
sdkennedy2/inline-dynamic-imports-shared-config
Apr 13, 2026
Merged

[APPS] Use manualChunks for self-contained backend function builds#317
yoannmoinet merged 1 commit intomasterfrom
sdkennedy2/inline-dynamic-imports-shared-config

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented Apr 7, 2026

Motivation

PR #317 originally moved inlineDynamicImports: true into the shared backend build config and refactored production builds to loop one vite.build() per function. A coworker pointed out that manualChunks: () => '[name]' — a pattern already used in this repo's own rollup config — achieves the same "no code splitting" goal while supporting multiple entry points in a single build call.

Changes

Replaced inlineDynamicImports: true with manualChunks: () => '[name]' in the shared backend build config. This lets us batch all backend functions into a single vite.build() call instead of looping one call per function.

The key difference: inlineDynamicImports only works with a single entry point (Rollup limitation), forcing us to build each function individually. manualChunks assigns all modules to the entry chunk, preventing code splitting while supporting multiple entries. This is the same pattern used at packages/tools/src/rollupConfig.mjs:193.

build-config.ts: Swapped inlineDynamicImports: true for manualChunks: () => '[name]' and moved entryFileNames: '[name].js' into the base config.

build-backend-functions.ts: Replaced the per-function loop (N vite.build() calls) with a single batched build — all virtual entries and inputs are collected up front, one build produces all outputs. Removes the no-await-in-loop eslint disable, emptyOutDir: false workaround, and per-function overrides.

dev-server.ts: No changes — builds one function per request and inherits the new config automatically.

QA Instructions

  1. Scaffold or use an existing test app with 2+ backend functions
  2. Link local build-plugins via yarn dev
  3. Run vite build — verify each backend function produces a self-contained .js file
  4. Run vite dev server — verify /__dd/executeAction still works for each function

Blast Radius

  • Only affects the apps plugin's backend function build pipeline
  • No changes to the main client build or any other plugin
  • The dev server path is unchanged (still builds one function per request)

Documentation

Copy link
Copy Markdown
Collaborator Author

sdkennedy2 commented Apr 7, 2026

@sdkennedy2 sdkennedy2 changed the title Move inlineDynamicImports to shared build config, simplify per-function build [APPS] Move inlineDynamicImports to shared backend build config Apr 7, 2026
@datadog-official
Copy link
Copy Markdown

datadog-official bot commented Apr 7, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3877b11 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

Base automatically changed from sdkennedy2/apps-vite-dev-server to master April 7, 2026 19:37
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/inline-dynamic-imports-shared-config branch from 6898cb6 to 3877b11 Compare April 7, 2026 19:54
@sdkennedy2 sdkennedy2 marked this pull request as ready for review April 8, 2026 15:26
@sdkennedy2 sdkennedy2 requested a review from yoannmoinet as a code owner April 8, 2026 15:26
@sdkennedy2 sdkennedy2 changed the title [APPS] Move inlineDynamicImports to shared backend build config [APPS] Use manualChunks for self-contained backend function builds Apr 8, 2026
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/inline-dynamic-imports-shared-config branch 3 times, most recently from 992368d to 3877b11 Compare April 9, 2026 13:48
Copy link
Copy Markdown
Member

@yoannmoinet yoannmoinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are working on customer's machine with this, I'd advocate for tight performances on this.

Not needed right away in this PR directly (so we can ship it asap), but in a soon-ish follow-up to have the builds made in parallel instead of sequentially, so its faster for the user.

Since this is something susceptible to run in CI, it will need some queueing system, in order not to flood the CPUs and memory capacities.

Multiple leads for it:

  • the internal async-queue plugin, that allows you to defer the build and let the lifecycles of the build-plugins continue uninterrupted, but still hold the build process until these are finished. Works as a fire-and-forget deferral.
  • PQueue usage with concurrency, example

@yoannmoinet yoannmoinet merged commit bbe8f31 into master Apr 13, 2026
7 checks passed
@yoannmoinet yoannmoinet deleted the sdkennedy2/inline-dynamic-imports-shared-config branch April 13, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants