github evanw/esbuild v0.14.3

latest releases: v0.24.0, v0.23.1, v0.23.0...
2 years ago
  • Pass the current esbuild instance to JS plugins (#1790)

    Previously JS plugins that wanted to run esbuild had to require('esbuild') to get the esbuild object. However, that could potentially result in a different version of esbuild. This is also more complicated to do outside of node (such as within a browser). With this release, the current esbuild instance is now passed to JS plugins as the esbuild property:

    let examplePlugin = {
      name: 'example',
      setup(build) {
        console.log(build.esbuild.version)
        console.log(build.esbuild.transformSync('1+2'))
      },
    }
  • Disable calc() transform for results with non-finite numbers (#1839)

    This release disables minification of calc() expressions when the result contains NaN, -Infinity, or Infinity. These numbers are valid inside of calc() expressions but not outside of them, so the calc() expression must be preserved in these cases.

  • Move "use strict" before injected shim imports (#1837)

    If a CommonJS file contains a "use strict" directive, it could potentially be unintentionally disabled by esbuild when using the "inject" feature when bundling is enabled. This is because the inject feature was inserting a call to the initializer for the injected file before the "use strict" directive. In JavaScript, directives do not apply if they come after a non-directive statement. This release fixes the problem by moving the "use strict" directive before the initializer for the injected file so it isn't accidentally disabled.

  • Pass the ignored path query/hash suffix to onLoad plugins (#1827)

    The built-in onResolve handler that comes with esbuild can strip the query/hash suffix off of a path during path resolution. For example, url("fonts/icons.eot?#iefix") can be resolved to the file fonts/icons.eot. For context, IE8 has a bug where it considers the font face URL to extend to the last ) instead of the first ). In the example below, IE8 thinks the URL for the font is Example.eot?#iefix') format('eot'), url('Example.ttf') format('truetype so by adding ?#iefix, IE8 thinks the URL has a path of Example.eot and a query string of ?#iefix') format('eot... and can load the font file:

    @font-face {
      font-family: 'Example';
      src: url('Example.eot?#iefix') format('eot'), url('Example.ttf') format('truetype');
    }

    However, the suffix is not currently passed to esbuild and plugins may want to use this suffix for something. Previously plugins had to add their own onResolve handler if they wanted to use the query suffix. With this release, the suffix can now be returned by plugins from onResolve and is now passed to plugins in onLoad:

    let examplePlugin = {
      name: 'example',
      setup(build) {
        build.onResolve({ filter: /.*/ }, args => {
          return { path: args.path, suffix: '?#iefix' }
        })
    
        build.onLoad({ filter: /.*/ }, args => {
          console.log({ path: args.path, suffix: args.suffix })
        })
      },
    }

    The suffix is deliberately not included in the path that's provided to plugins because most plugins won't know to handle this strange edge case and would likely break. Keeping the suffix out of the path means that plugins can opt-in to handling this edge case if they want to, and plugins that aren't aware of this edge case will likely still do something reasonable.

Don't miss a new esbuild release

NewReleases is sending notifications on new releases.