alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)

Home Page:https://ice.work

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Split server chunk for each page when format is cjs

ClarkXia opened this issue · comments

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