github evanw/esbuild v0.16.12

latest releases: v0.21.3, v0.21.2, v0.21.1...
16 months ago
  • Loader defaults to js for extensionless files (#2776)

    Certain packages contain files without an extension. For example, the yargs package contains the file yargs/yargs which has no extension. Node, Webpack, and Parcel can all understand code that imports yargs/yargs because they assume that the file is JavaScript. However, esbuild was previously unable to understand this code because it relies on the file extension to tell it how to interpret the file. With this release, esbuild will now assume files without an extension are JavaScript files. This can be customized by setting the loader for "" (the empty string, representing files without an extension) to another loader. For example, if you want files without an extension to be treated as CSS instead, you can do that like this:

    • CLI:

      esbuild --bundle --loader:=css
      
    • JS:

      esbuild.build({
        bundle: true,
        loader: { '': 'css' },
      })
    • Go:

      api.Build(api.BuildOptions{
        Bundle: true,
        Loader: map[string]api.Loader{"": api.LoaderCSS},
      })

    In addition, the "type" field in package.json files now only applies to files with an explicit .js, .jsx, .ts, or .tsx extension. Previously it was incorrectly applied by esbuild to all files that had an extension other than .mjs, .mts, .cjs, or .cts including extensionless files. So for example an extensionless file in a "type": "module" package is now treated as CommonJS instead of ESM.

Don't miss a new esbuild release

NewReleases is sending notifications on new releases.