Skip to content

feat(packages/sui-compiler-config): preserve webpack magic comments in TS compilation#1976

Open
paulusrex wants to merge 4 commits intomasterfrom
feat/sui-compiler-config-not-minify
Open

feat(packages/sui-compiler-config): preserve webpack magic comments in TS compilation#1976
paulusrex wants to merge 4 commits intomasterfrom
feat/sui-compiler-config-not-minify

Conversation

@paulusrex
Copy link
Copy Markdown
Contributor

@paulusrex paulusrex commented Mar 26, 2026

Description

SWC's minify: true was hardcoded in getSWCConfig, causing it to run minification
inside webpack's swc-loader before webpack processes magic comments like
/* webpackChunkName: "..." */. This strips the comments, resulting in unnamed chunks
and broken CSS loading in SSR.

Changes

Two small, focused changes:

  1. sui-compiler-config/src/index.js — Removed the hardcoded minify: true from getSWCConfig() and added a new preserveComments option. When true, it outputs minify: { format: { comments: 'all' } } to instruct SWC to keep all comments (including webpack magic comments).

  2. sui-bundler/shared/module-rules-compiler.js — The TypeScript SWC rule now passes preserveComments: true so that webpack magic comments survive the loader phase.

Before / After

// packages/sui-compiler-config/src/index.js — before
const getSWCConfig = ({isModern, isTypeScript, compileToCJS}) => {
  return { minify: true, jsc: { ... } }
}

// packages/sui-compiler-config/src/index.js — after
const getSWCConfig = ({isModern, isTypeScript, compileToCJS, preserveComments = false}) => {
  const minifyOptions = preserveComments ? {minify: {format: {comments: 'all'}}} : {}
  return { jsc: { ..., ...minifyOptions, ... } }
}

// packages/sui-bundler/shared/module-rules-compiler.js — before
options: getSWCConfig({isModern: false, isTypeScript: true})

// packages/sui-bundler/shared/module-rules-compiler.js — after
options: getSWCConfig({isModern: false, isTypeScript: true, preserveComments: true})

Context

Fotocasa wants to implement TypeScript in their project and the removal of magic comments causes that chunking does not work properly for CSS, producing flickering in dev and broken production bundles.

Impact analysis

  • The hardcoded minify: true has been removed. This is safe because production minification is handled independently by TerserPlugin/esbuild in a later webpack phase (sui-bundler/shared/minify-js.js).
  • Only the TypeScript compilation path in sui-bundler passes preserveComments: true. Other callers (sui-js-compiler, sui-test) are unaffected — they get the same behaviour as before minus the redundant SWC-level minification.
  • The change is 2 files, +4 / -3 lines.


return {
minify: true,
minify,
Copy link
Copy Markdown
Member

@andresz1 andresz1 Mar 27, 2026

Choose a reason for hiding this comment

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

Can we set this false only if ts is enabled and the flag is set to true otherwise it will affect all applications (at least for now)

@paulusrex paulusrex force-pushed the feat/sui-compiler-config-not-minify branch from 7be0b3b to 5e32707 Compare March 31, 2026 20:34
@paulusrex paulusrex changed the title feat(packages/sui-compiler-config): add minify parameter defaulting to false feat(packages/sui-compiler-config): preserve webpack magic comments in TS compilation Mar 31, 2026
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.

3 participants