Back to Lowdefy

Migration: `public/styles.less` → Theme YAML + CSS

packages/codemods/v5-0-0/10-detect-styles-less.md

5.2.03.5 KB
Original Source

Migration: public/styles.less → Theme YAML + CSS

Context

Lowdefy v4 supported public/styles.less for custom styling with Less variables that mapped to antd's Less-based theming. Antd v6 uses CSS-in-JS with design tokens. Less is no longer processed by the build.

What to Do

  1. Check if public/styles.less exists
  2. If it does, parse its content and split into two buckets:
    • Less variables → map to antd design tokens in lowdefy.yaml theme config
    • Plain CSS / complex Less → convert to public/styles.css

Known Less Variable → Token Mapping

Less VariableAntd Token
@primary-colorcolorPrimary
@link-colorcolorLink
@success-colorcolorSuccess
@warning-colorcolorWarning
@error-colorcolorError
@font-size-basefontSize
@heading-colorcolorTextHeading
@text-colorcolorText
@text-color-secondarycolorTextSecondary
@disabled-colorcolorTextDisabled
@border-radius-baseborderRadius
@border-color-basecolorBorder
@box-shadow-baseboxShadow
@body-backgroundcolorBgContainer

For each variable found, generate the equivalent theme.antd.token YAML:

yaml
# Add to lowdefy.yaml
theme:
  antd:
    token:
      colorPrimary: '#1890ff'
      fontSize: 14
      borderRadius: 4

Complex Less (manual conversion needed)

Flag these for manual conversion:

  • Less mixins (.mixin())
  • Less functions (darken(), lighten(), fade())
  • Nested selectors with &
  • @import statements (other than antd imports)
  • Any Less-specific syntax

Convert remaining plain CSS to public/styles.css.

Files to Check

Check: public/styles.less

Examples

Before — styles.less

less
@primary-color: #1890ff;
@border-radius-base: 6px;
@font-size-base: 14px;

.custom-header {
  padding: 16px;
  background: @primary-color;
}

After — lowdefy.yaml addition

yaml
theme:
  antd:
    token:
      colorPrimary: '#1890ff'
      borderRadius: 6
      fontSize: 14

After — public/styles.css (for non-variable CSS)

css
.custom-header {
  padding: 16px;
  background: var(--ant-color-primary);
}

Edge Cases

  • If styles.less contains only variables and no custom CSS, only the lowdefy.yaml theme config is needed — no styles.css
  • Less expressions like darken(@primary-color, 10%) have no direct token equivalent — flag these for manual conversion to CSS custom properties or hardcoded values
  • Some apps may import antd Less files (@import '~antd/dist/antd.less') — these lines can be removed entirely (antd v6 doesn't use Less)
  • If lowdefy.yaml already has a theme: section, merge the tokens into it

CRITICAL: Delete public/styles.less

After migrating, you MUST delete public/styles.less. The v5 build checks for this file and throws a fatal ConfigError if it exists — even if it's empty. The build will not proceed until the file is removed.

bash
rm public/styles.less

Verification

  1. public/styles.less must NOT exist — the build will fail if it does
  2. Theme tokens are in lowdefy.yaml under theme.antd.token
  3. Custom CSS (if any) is in public/styles.css
  4. The app builds without Less processing errors