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

Split server chunk for each page when format is cjs #6842

Closed
ClarkXia opened this issue Mar 27, 2024 · 0 comments
Closed

Split server chunk for each page when format is cjs #6842

ClarkXia opened this issue Mar 27, 2024 · 0 comments
Labels

Comments

@ClarkXia
Copy link
Collaborator

Summary | 概述

No response

Motivation | 背景

When formatted as CommonJS (CJS), the server bundle will encompass all pages, leading to an increased bundle size as the number of pages grows. To optimize, we should bundle only the necessary server source code required for operation.

Usage example | 使用示例

No response

Detailed design | 方案设计

A new configuration option will be introduced to manage the bundling strategy:

import { defineConfig } from '@ice/app';

export default defineConfig(() => ({
  server: {
    format: 'cjs',
    // Bundle strategy `page` will only works in cjs format.
    bundle: 'page',
  }
}));

When bundle: 'page' is set, the following actions will be executed:

  • Multiple server entries will be generated, corresponding to each page path
  • Each entry will import only the essential components required for that specific page
  • esbuild will compile each entry in parallel
  • The name of the output file will correspond to the route's path

Additional context | 额外信息

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant