Skip to content

SVG minification depends on NODE_ENV but is not clearly documented or enforced #10024

@Abderrahmane-MERSTANI

Description

@Abderrahmane-MERSTANI

Description
SVG minification is conditionally applied based on the NODE_ENV environment variable.
If NODE_ENV is not explicitly set to "production", SVG files will not be optimized, even during builds intended for deployment.

Code concerned

const IS_PRODUCTION_BUILD = process.env.NODE_ENV === 'production';

const shouldMinifySVG = function (file) {
return IS_PRODUCTION_BUILD && file.path.match(/.svg$/);
};

Problems

NODE_ENV may be undefined or incorrectly set

Production builds may ship unminified SVG assets

Behavior is implicit and not obvious to contributors

Asset size optimization depends on external environment configuration

Expected Behavior

Production builds should reliably minify SVGs

Build behavior should be explicit and predictable

Developers should not need to guess environment requirements

Suggested Fix
Option 1: Provide a default fallback

const IS_PRODUCTION_BUILD =
process.env.NODE_ENV === 'production' || process.env.CI === 'true';

Option 2: Expose an explicit build flag

const IS_PRODUCTION_BUILD = process.env.MINIFY_ASSETS === 'true';

Option 3: Document the requirement clearly in the project README.

Impact

Smaller production bundles

More predictable build behavior

Easier onboarding for new contributors

Reduced risk of shipping unoptimized assets

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions