Skip to content

Bundle size increase due to CSS content duplication in stylesheet export #468

@dog-s-life

Description

@dog-s-life

Problem Description

When using rollup-plugin-postcss with CSS modules, the plugin generates duplicate CSS content in the output bundle, leading to unnecessary bundle size increase. This occurs because the same CSS content is stored twice:

  1. Once in the CSS variable (var ${cssVariableName})
  2. Again in the stylesheet export (export var stylesheet)

This duplication directly impacts the final bundle size, which is especially problematic for production builds where bundle size optimization is critical.

Current Behavior (Causing Bundle Bloat)

var css_248z = ".class { color: red; }";
var stylesheet = ".class { color: red; }";

// inject code

export { css_248z as default, stylesheet };
//# sourceMappingURL=...

Expected Behavior (Optimized)

var css_248z = ".class { color: red; }";
var stylesheet = css_248z;

// inject code

export { css_248z as default, stylesheet };
//# sourceMappingURL=...

Environment

  • rollup-plugin-postcss version: 4.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions