Skip to content

Constant folding in development builds #657

Closed
@Xiot

Description

I've noticed a case where the constant folding isn't happening where I thought it should.

It works great in tertirary operators, however it doesn't seem to fold with constant if conditions.

echo "if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react-dom.production.min.js');
} else {
  module.exports = require('./cjs/react-dom.development.js');
}" | esbuild --define:process.env.NODE_ENV=\"production\"

if (true) {
  module.exports = require("./cjs/react-dom.production.min.js");
} else {
  module.exports = require("./cjs/react-dom.development.js");
}

Looking at #371 it appears like that should be folded properly.

If I enable minification, it does do the proper foldinig.

echo "if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react-dom.production.min.js');
} else {
  module.exports = require('./cjs/react-dom.development.js');
}" | esbuild --define:process.env.NODE_ENV=\"production\" --minify

module.exports=require("./cjs/react-dom.production.min.js");

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