Publishing build plugin as non default export of a package

When authoring a build plugin, I’d love to be able to specify where the entry point is and put it where I would like in my package. Currently (as far as I know) it must be the main/default export of the package.

In my case I am publishing the build plugin along with some other utilities meant to be consumed by the user and used in their source code, so would love for the default export to be freed up for the things they are importing more frequently, and put the build plugin on an additional export path.

This could work by supporting non-default export paths in the netlify.toml file’s plugins section - for example:

[[plugins]]
  package = "@my-org/some-package/non-default-export"

or by supporting some kind of entry path in the manifest.yml (although not being forced into putting the manifest.yml at the root would also be nice)

name: my-build-plugin
entry: "dist/build-plugin/index.js"

or by looking for some non-standard key in package.json

{
   // rest of your package.json ...
  "netlify-build-plugin": "dist/build-plugin"
}

or by checking some non-default export path (like /netlify-build-plugin) first before trying the default export.

Thanks!

Build plugins require you to export specific constants (named exports) and not a default export. Something like:

export const onPreBuild = function() {
  console.log("Hello world from onPreBuild event!");
}

How’s the default export being used here?

If you export a default function that returns an object with the events as a property, that’s a different story.

I’m talking about the exports of the package itself, not the exports from the file that defines the build plugin logic. See Modules: Packages | Node.js v22.2.0 Documentation

So you can imagine something like

package.json

{
  "name": "@myorg/netlify",
  "exports": {
    ".": "./dist/index.js",
    "./build-plugin": "./dist/build-plugin
  },
  // ...

and then in netlify.toml

[[plugins]]
  package = "@myorg/netlify/build-plugin"