Skip to content

Merge adjacent layers in minification #211

@jacobrask

Description

@jacobrask

The following code

@import url('./layout/tokens.css') layer(theme);
@import url('./ornamental/tokens.css') layer(theme);
@import url('./layout/defaults.css') layer(defaults);

Currently bundles/minifies into

@layer theme {
  // layout/tokens.css content
}
@layer theme {
  // ornamental/tokens.css content
}
@layer defaults {
  // ornamental/tokens.css content
}

While it could minify to

@layer theme {
  // layout/tokens.css content
  // ornamental/tokens.css content
}
@layer defaults {
  // ornamental/tokens.css content
}

As a project grows into a large number of files this adds up in the total bundle.

As a further optimization it should even be possible to hoist the contents of any layer to the first occurrence of that layer, and always only output a single @layer for a unique name in any one bundle. That's the way the cascade works anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions