If you want to conditionally disable some development-only code and have it not be present in the final production bundle, right now the most straightforward way of doing this is to use the --define: flag along with a specially-named global variable. For example, consider the following code:
function main() {
DEV && doAnExpensiveCheck()
}
You can build this for development and production like this:
Development: esbuild --define:DEV=true
Production: esbuild --define:DEV=false
One drawback of this approach is that the resulting code crashes if you don't provide a value for DEV with --define:. In practice this isn't that big of a problem, and there are also various ways to work around this.
However, another approach that avoids this drawback is to use JavaScript label statements instead. That's what the --drop-labels= flag implements. For example, consider the following code:
function main() {
DEV: doAnExpensiveCheck()
}
With this release, you can now build this for development and production like this:
Development: esbuild
Production: esbuild --drop-labels=DEV
This means that code containing optional development-only checks can now be written such that it's safe to run without any additional configuration. The --drop-labels= flag takes comma-separated list of multiple label names to drop.
Avoid causing unhandledRejection during shutdown (#3219)
All pending esbuild JavaScript API calls are supposed to fail if esbuild's underlying child process is unexpectedly terminated. This can happen if SIGINT is sent to the parent node process with Ctrl+C, for example. Previously doing this could also cause an unhandled promise rejection when esbuild attempted to communicate this failure to its own child process that no longer exists. This release now swallows this communication failure, which should prevent this internal unhandled promise rejection. This change means that you can now use esbuild's JavaScript API with a custom SIGINT handler that extends the lifetime of the node process without esbuild's internals causing an early exit due to an unhandled promise rejection.
Update browser compatibility table scripts
The scripts that esbuild uses to compile its internal browser compatibility table have been overhauled. Briefly:
Converted from JavaScript to TypeScript
Fixed some bugs that resulted in small changes to the table
This change means it's now much easier to keep esbuild's internal compatibility tables up to date. You can review the table changes here if you need to debug something about this change:
If you want to conditionally disable some development-only code and have it not be present in the final production bundle, right now the most straightforward way of doing this is to use the --define: flag along with a specially-named global variable. For example, consider the following code:
function main() {
DEV && doAnExpensiveCheck()
}
You can build this for development and production like this:
Development: esbuild --define:DEV=true
Production: esbuild --define:DEV=false
One drawback of this approach is that the resulting code crashes if you don't provide a value for DEV with --define:. In practice this isn't that big of a problem, and there are also various ways to work around this.
However, another approach that avoids this drawback is to use JavaScript label statements instead. That's what the --drop-labels= flag implements. For example, consider the following code:
function main() {
DEV: doAnExpensiveCheck()
}
With this release, you can now build this for development and production like this:
Development: esbuild
Production: esbuild --drop-labels=DEV
This means that code containing optional development-only checks can now be written such that it's safe to run without any additional configuration. The --drop-labels= flag takes comma-separated list of multiple label names to drop.
Avoid causing unhandledRejection during shutdown (#3219)
All pending esbuild JavaScript API calls are supposed to fail if esbuild's underlying child process is unexpectedly terminated. This can happen if SIGINT is sent to the parent node process with Ctrl+C, for example. Previously doing this could also cause an unhandled promise rejection when esbuild attempted to communicate this failure to its own child process that no longer exists. This release now swallows this communication failure, which should prevent this internal unhandled promise rejection. This change means that you can now use esbuild's JavaScript API with a custom SIGINT handler that extends the lifetime of the node process without esbuild's internals causing an early exit due to an unhandled promise rejection.
Update browser compatibility table scripts
The scripts that esbuild uses to compile its internal browser compatibility table have been overhauled. Briefly:
Converted from JavaScript to TypeScript
Fixed some bugs that resulted in small changes to the table
This change means it's now much easier to keep esbuild's internal compatibility tables up to date. You can review the table changes here if you need to debug something about this change:
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Bumps github.com/evanw/esbuild from 0.18.12 to 0.18.13.
Release notes
Sourced from github.com/evanw/esbuild's releases.
Changelog
Sourced from github.com/evanw/esbuild's changelog.
Commits
12a8a25
publish 0.18.13 to npmb8db71b
fix a bug with "HandlesImportErrors"9b83e55
fix #2398: add the--drop-labels=
optionc0f0380
release notes aboutmake compat-table
changes95feb2e
generate css compat table from data sourcesc7cfcd7
change css prefix table from map to array8577fe9
pre-sort css compat tableaf453f2
makecompat-table
update optionalaf1d35c
add "mdn" as a compat table data sourceb07e747
only loop through desired data in "caniuse"Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)