Skip to content

[Feature]: Align webpack DefinePlugin for destructuring optimization #8120

@chenjiahan

Description

@chenjiahan

What problem does this feature solve?

Align webpack's DefinePlugin for destructuring optimization.

For example:

new DefinePlugin({
  "process.env": {
    NODE_ENV: '"development"',
    PUBLIC_URL: '""',
    WDS_SOCKET_HOST: undefined,
    WDS_SOCKET_PATH: undefined,
    WDS_SOCKET_PORT: undefined,
    FAST_REFRESH: "true",
  },
})
  • Input:
const { NODE_ENV } = process.env;

console.log("process.env.NODE_ENV", NODE_ENV);
  • Output (webpack):
const { NODE_ENV } = ({"NODE_ENV":"development"});

console.log("process.env.NODE_ENV", NODE_ENV);
  • Output (Rspack):
const { NODE_ENV } = ({ "NODE_ENV":"development","PUBLIC_URL":"","WDS_SOCKET_HOST":undefined,"WDS_SOCKET_PATH":undefined,"WDS_SOCKET_PORT":undefined,"FAST_REFRESH":true });

console.log("process.env.NODE_ENV", NODE_ENV);

A minimal demo: https://github.com/chenjiahan/rspack-repro-define-destructuring

What does the proposed API of configuration look like?

Internal optimization, no public API required.

Metadata

Metadata

Assignees

Labels

featNew feature or requestteamThe issue/pr is created by the member of Rspack.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions