-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 with regex #163
Comments
I suggest using a normal if statement with a if (DEBUG) {
... debug only code ...
} Then debug builds can use If you aren't using esbuild for debug builds or don't want to pass |
Yeah that would work logic-wise but you know those comments are like C preprocessor so the code will be removed which results in a smaller bundle size. And some of us do care about the bundle size right? |
Ah, sorry. More detail: |
Ah cool, thanks! I will try it out. |
A C like preprocessor can't be replaced by JS logic: Object.assign(pc, function () {
// #ifdef DEBUG
var _debugLogging = false;
// #endif // #ifdef DEBUG
try {
// #endif
script[method](arg);
// #ifdef DEBUG
} catch (ex) {
// disable script if it fails to call method
script.enabled = false;
if (!script._callbacks || !script._callbacks.error) {
console.warn('unhandled exception while calling "' + method + '" for "' + script.__scriptType.__name + '" script: ', ex);
console.error(ex);
}
script.fire('error', ex, method);
this.fire('error', script, ex, method);
}
// #endif etc. |
I'm not planning to build a preprocessor like that into esbuild because that's not part of the language. Cases like those will have to be addressed by running the preprocessor separately somehow. One way to do this might be plugins if those are eventually added. See #111. |
FWIW this should be very possible to do with the plugin API now that it's been released. |
I still don't see how that solves for macros in a usable way. From the docs: So either I guess it just boils down to "either esbuild supports it natively" or "sticking to other bundlers which are easy to extend via JS while not losing performance" |
That warning was more for slow plugins like Babel that parse the code into an AST. If you can do TL;DR: I think it can be pretty fast. I ran a simple JavaScript plugin that tests each file for the presence of |
Here is a plugin that adds support for |
Hi,
Is there a way to replace a whole code block with
--define
?So we have some blocks should only be in the debug build i.e console.log etc. They are delimited with a pair of comments
I think if we could use a regex in
--define
then that would be it.Or do you have any suggestion/workaround for our issue? Thanks
The text was updated successfully, but these errors were encountered: