-
Allow entry points outside of the
outbase
directory (#634)When esbuild generates the output path for a bundled entry point, it computes the relative path from the
outbase
directory to the input entry point file and then joins that relative path to the output directory. For example, if there are two entry pointssrc/pages/home/index.ts
andsrc/pages/about/index.ts
, the outbase directory issrc
, and the output directory isout
, the output directory will containout/pages/home/index.js
andout/pages/about/index.js
.However, this means that the
outbase
directory is expected to contain all entry point files (even implicit entry point files fromimport()
expressions). If an entry point isn't under the outbase directory then esbuild will to try to write the output file outside of the output directory, since the path of the entry point relative tooutbase
will start with../
which is then joined to the output directory. This is unintentional. All output files are supposed to be written inside of the output directory.This release fixes the problem by creating a directory with the name
_.._
in the output directory for output file paths of entry points that are not inside theoutbase
directory. So if the previous example was bundled with an outbase directory oftemp
, the output directory will containout/_.._/pages/home/index.js
andout/_.._/pages/about/index.js
. Doing this instead of stripping the leading../
off the relative path is necessary to avoid collisions between different entry points with the same path suffix. -
Minification improvements
This release contains the following minification improvements:
-
Expressions of the form
!(a == b)
are now converted toa != b
. This also applies similarly for the other three equality operators. -
A trailing
continue;
statement inside the body of a loop is now removed. -
Minification can now omit certain
continue
andreturn
statements when it's implied by control flow:// Before minification function fn() { if (a) return; while (b) { if (c) continue; d(); } } // After minification function fn() { if (!a) for (; b; ) c || d(); }
-
Certain single-use variables are now inlined if the use directly follows the variable:
// Before minification let result = fn(); let callback = result.callback; return callback.call(this);
// After minification return fn().callback.call(this);
This transformation is only done when it's safe to do so. The safety conditions are complex but at a high level, an expression cannot be reordered past another expression if either of them could possibly have side effects.
-