v0.19.0
This release deliberately contains backwards-incompatible changes. To avoid automatically picking up releases like this, you should either be pinning the exact version of esbuild in your package.json file (recommended) or be using a version range syntax that only accepts patch upgrades such as ^0.18.0 or ~0.18.0. See npm's documentation about semver for more information.
-
Handle import paths containing wildcards (#56, #700, #875, #976, #2221, #2515)
This release introduces wildcards in import paths in two places:
-
Entry points
You can now pass a string containing glob-style wildcards such as
./src/*.tsas an entry point and esbuild will search the file system for files that match the pattern. This can be used to easily pass esbuild all files with a certain extension on the command line in a cross-platform way. Previously you had to rely on the shell to perform glob expansion, but that is obviously shell-dependent and didn't work at all on Windows. Note that to use this feature on the command line you will have to quote the pattern so it's passed verbatim to esbuild without any expansion by the shell. Here's an example:esbuild --minify "./src/*.ts" --outdir=outSpecifically the
*character will match any character except for the/character, and the/**/character sequence will match a path separator followed by zero or more path elements. Other wildcard operators found in glob patterns such as?and[...]are not supported. -
Run-time import paths
Import paths that are evaluated at run-time can now be bundled in certain limited situations. The import path expression must be a form of string concatenation and must start with either
./or../. Each non-string expression in the string concatenation chain becomes a wildcard. The*wildcard is chosen unless the previous character is a/, in which case the/**/*character sequence is used. Some examples:// These two forms are equivalent const json1 = await import('./data/' + kind + '.json') const json2 = await import(`./data/${kind}.json`)
This feature works with
require(...)andimport(...)because these can all accept run-time expressions. It does not work withimportandexportstatements because these cannot accept run-time expressions. If you want to prevent esbuild from trying to bundle these imports, you should move the string concatenation expression outside of therequire(...)orimport(...). For example:// This will be bundled const json1 = await import('./data/' + kind + '.json') // This will not be bundled const path = './data/' + kind + '.json' const json2 = await import(path)
Note that using this feature means esbuild will potentially do a lot of file system I/O to find all possible files that might match the pattern. This is by design, and is not a bug. If this is a concern, I recommend either avoiding the
/**/pattern (e.g. by not putting a/before a wildcard) or using this feature only in directory subtrees which do not have many files that don't match the pattern (e.g. making a subdirectory for your JSON files and explicitly including that subdirectory in the pattern).
-
-
Path aliases in
tsconfig.jsonno longer count as packages (#2792, #3003, #3160, #3238)Setting
--packages=externaltells esbuild to make all import paths external when they look like a package path. For example, an import of./foo/baris not a package path and won't be external while an import offoo/baris a package path and will be external. However, thepathsfield intsconfig.jsonallows you to create import paths that look like package paths but that do not resolve to packages. People do not want these paths to count as package paths. So with this release, the behavior of--packages=externalhas been changed to happen after thetsconfig.jsonpath remapping step. -
Use the
local-cssloader for.module.cssfiles by default (#20)With this release the
cssloader is still used for.cssfiles except that.module.cssfiles now use thelocal-cssloader. This is a common convention in the web development community. If you need.module.cssfiles to use thecssloader instead, then you can override this behavior with--loader:.module.css=css.