|
1 | 1 | # Changelog |
2 | 2 |
|
| 3 | +## Unreleased |
| 4 | + |
| 5 | +* Handle import paths containing wildcards ([#56](https://github.com/evanw/esbuild/issues/56), [#700](https://github.com/evanw/esbuild/issues/700), [#875](https://github.com/evanw/esbuild/issues/875), [#976](https://github.com/evanw/esbuild/issues/976), [#2221](https://github.com/evanw/esbuild/issues/2221), [#2515](https://github.com/evanw/esbuild/issues/2515)) |
| 6 | + |
| 7 | + This release introduces wildcards in import paths in two places: |
| 8 | + |
| 9 | + * **Entry points** |
| 10 | + |
| 11 | + You can now pass a string containing glob-style wildcards such as `./src/*.ts` as 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: |
| 12 | + |
| 13 | + ```sh |
| 14 | + esbuild --minify "./src/*.ts" --outdir=out |
| 15 | + ``` |
| 16 | + |
| 17 | + Specifically 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. |
| 18 | + |
| 19 | + * **Run-time import paths** |
| 20 | + |
| 21 | + 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: |
| 22 | + |
| 23 | + ```js |
| 24 | + // These two forms are equivalent |
| 25 | + const json1 = await import('./data/' + kind + '.json') |
| 26 | + const json2 = await import(`./data/${kind}.json`) |
| 27 | + ``` |
| 28 | + |
| 29 | + This feature works with `require(...)` and `import(...)` because these can all accept run-time expressions. It does not work with `import` and `export` statements 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 the `require(...)` or `import(...)`. For example: |
| 30 | + |
| 31 | + ```js |
| 32 | + // This will be bundled |
| 33 | + const json1 = await import('./data/' + kind + '.json') |
| 34 | +
|
| 35 | + // This will not be bundled |
| 36 | + const path = './data/' + kind + '.json' |
| 37 | + const json2 = await import(path) |
| 38 | + ``` |
| 39 | + |
| 40 | + 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). |
| 41 | +
|
3 | 42 | ## 0.18.20 |
4 | 43 |
|
5 | 44 | * Support advanced CSS `@import` rules ([#953](https://github.com/evanw/esbuild/issues/953), [#3137](https://github.com/evanw/esbuild/issues/3137)) |
|
0 commit comments