Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chenjiahan opened this issue Oct 15, 2024 · 0 comments
Open
Assignees
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.

Comments

@chenjiahan
Copy link
Member

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.

@chenjiahan chenjiahan added feat New feature or request pending triage The issue/PR is currently untouched. and removed pending triage The issue/PR is currently untouched. labels Oct 15, 2024
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

No branches or pull requests

2 participants