Skip to content

feat: improve support for destructing in DefinePlugin #19638

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hai-x
Copy link
Member

@hai-x hai-x commented Jun 28, 2025

What kind of change does this PR introduce?

Fixes #5392 #14800 (comment).

There are some cases that can't be supported:

  1. Some destructured properties might not be defined in DefinePlugin, but could exist at runtime.
const { NODE_ENV, UNKNOWN } = process.env
  1. Some destructured properties may be defined across multiple DefinePlugin.
const { NODE_ENV, FOO, BAR } = process.env
module.exports={
  // ...
  plugins: [
    // ...
    new DefinePlugin({
      NODE_ENV: "development"
    }),
    new DefinePlugin({
      FOO: "foo",
      BAR: "bar"
  })]
}

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

Nothing

Copy link

codspeed-hq bot commented Jun 28, 2025

CodSpeed Performance Report

Merging #19638 will degrade performances by 94.12%

Comparing destructing-for-define-plugin (cae5f4d) with main (5bcd259)

Summary

⚡ 3 improvements
❌ 3 regressions
✅ 127 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "cache-filesystem", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 224.3 ms 14 ms ×16
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 42.3 ms 35.1 ms +20.55%
benchmark "devtool-eval-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 39.3 ms 9.8 ms ×4
benchmark "devtool-source-map", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 10.4 ms 64.1 ms -83.8%
benchmark "minimal", scenario '{"name":"mode-development","mode":"development"}' 24.2 ms 30.4 ms -20.27%
benchmark "three-long", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 13.2 ms 224.3 ms -94.12%

@hai-x hai-x force-pushed the destructing-for-define-plugin branch from 9d6be32 to 2e0eadb Compare June 28, 2025 17:34
@hai-x hai-x force-pushed the destructing-for-define-plugin branch from 2e0eadb to ccbe94e Compare June 28, 2025 17:55
@hai-x hai-x marked this pull request as ready for review June 28, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EnvironmentPlugin: destructuring process.env doesn't work
1 participant