-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Define doesn't apply to optionally chained variables #2324
Comments
echo 'console.log(a?.b)' | esbuild --define:a='{"b":"x"}' var define_a_default = { b: "x" };
console.log(define_a_default?.b); |
I don't have time to check right now, but I'd want to check how this feature behaves in other bundlers before implementing this (e.g. Webpack). Ideally esbuild would behave the same way. |
This would work, but in my case the |
@evanw This behavior works in Webpack using DefinePlugin: // webpack.config.js
const webpack = require('webpack');
/** @type {import('webpack').Configuration} */
const config = {
mode: 'production',
entry: './index.js',
output: {
filename: './out.js'
},
plugins: [
new webpack.DefinePlugin({
'a.b': '"x"'
})
]
}
module.exports = config; // index.js
console.log(a.b);
console.log(a?.b); // out.js
console.log("x"),console.log("x"); |
hansottowirtz
changed the title
Define doesn't apply optionally chained variables
Define doesn't apply to optionally chained variables
Jun 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to replace
a?.b
with a variable, but it's not possible yet to use define for this. I think it would be valid in every case to add this functionality.Example:
Would it be possible to implement this as well, or is there some kind of workaround available?
The text was updated successfully, but these errors were encountered: