alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
https://ice.work
MIT License
17.8k stars 2.09k forks source link

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

Closed ClarkXia closed 2 months ago

ClarkXia commented 3 months ago

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:

Additional context | 额外信息

No response