Skip to content

v0.14.18

Compare
Choose a tag to compare
@github-actions github-actions released this 02 Feb 19:46
  • Add the --mangle-cache= feature (#1977)

    This release adds a cache API for the newly-released --mangle-props= feature. When enabled, all mangled property renamings are recorded in the cache during the initial build. Subsequent builds reuse the renamings stored in the cache and add additional renamings for any newly-added properties. This has a few consequences:

    • You can customize what mangled properties are renamed to by editing the cache before passing it to esbuild (the cache is a map of the original name to the mangled name).

    • The cache serves as a list of all properties that were mangled. You can easily scan it to see if there are any unexpected property renamings.

    • You can disable mangling for individual properties by setting the renamed value to false instead of to a string. This is similar to the --reserve-props= setting but on a per-property basis.

    • You can ensure consistent renaming between builds (e.g. a main-thread file and a web worker, or a library and a plugin). Without this feature, each build would do an independent renaming operation and the mangled property names likely wouldn't be consistent.

    Here's how to use it:

    • CLI

      $ esbuild example.ts --mangle-props=_$ --mangle-cache=cache.json
    • JS API

      let result = await esbuild.build({
        entryPoints: ['example.ts'],
        mangleProps: /_$/,
        mangleCache: {
          customRenaming_: '__c',
          disabledRenaming_: false,
        },
      })
      let updatedMangleCache = result.mangleCache
    • Go API

      result := api.Build(api.BuildOptions{
        EntryPoints: []string{"example.ts"},
        MangleProps: "_$",
        MangleCache: map[string]interface{}{
          "customRenaming_":   "__c",
          "disabledRenaming_": false,
        },
      })
      updatedMangleCache := result.MangleCache

    The above code would do something like the following:

    // Original code
    x = {
      customRenaming_: 1,
      disabledRenaming_: 2,
      otherProp_: 3,
    }
    
    // Generated code
    x = {
      __c: 1,
      disabledRenaming_: 2,
      a: 3
    };
    
    // Updated mangle cache
    {
      "customRenaming_": "__c",
      "disabledRenaming_": false,
      "otherProp_": "a"
    }
  • Add opera and ie as possible target environments

    You can now target Opera and/or Internet Explorer using the --target= setting. For example, --target=opera45,ie9 targets Opera 45 and Internet Explorer 9. This change does not add any additional features to esbuild's code transformation pipeline to transform newer syntax so that it works in Internet Explorer. It just adds information about what features are supported in these browsers to esbuild's internal feature compatibility table.

  • Minify typeof x !== 'undefined' to typeof x < 'u'

    This release introduces a small improvement for code that does a lot of typeof checks against undefined:

    // Original code
    y = typeof x !== 'undefined';
    
    // Old output (with --minify)
    y=typeof x!="undefined";
    
    // New output (with --minify)
    y=typeof x<"u";

    This transformation is only active when minification is enabled, and is disabled if the language target is set lower than ES2020 or if Internet Explorer is set as a target environment. Before ES2020, implementations were allowed to return non-standard values from the typeof operator for a few objects. Internet Explorer took advantage of this to sometimes return the string 'unknown' instead of 'undefined'. But this has been removed from the specification and Internet Explorer was the only engine to do this, so this minification is valid for code that does not need to target Internet Explorer.