Skip to content

[Feature]: When providing --env-mode the .env files should be read in reverse order. #4885

@ashwin-gairola

Description

@ashwin-gairola

What problem does this feature solve?

According to the documentation:

Rsbuild also supports reading .env.[mode] and .env.[mode].local files. You can specify the env mode using the --env-mode flag.

For example, set the env mode as test:

npx rsbuild dev --env-mode test

Rsbuild will then read the following files in sequence:

.env
.env.local
.env.test
.env.test.local

Wouldn't it make sense to read it in reverse? The .env.test.local file has a more specific use-case than .env by definition, so wouldn't one want it to be read first? I am indeed facing this same use-case where I want a .env.<mode>.local file read in precedence to the .env file, which is only used as a template for other .env files.

What does the proposed API look like?

Rsbuild should read the following files in sequence (more specific files should be given precedence):

.env.test.local
.env.test
.env.local
.env

OR

The developer can simply specify the exact .env file they want read.

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