unjs / unbuild

📦 A unified JavaScript build system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prefer `publishConfig` from `package.json` when defined

humphd opened this issue · comments

Describe the feature

I'm using unbuild in a pnpm monorepo. I love how unbuild works seamlessly with the definitions in my package.json to produce CommonJS, ESM, and Types automatically. However, I've run into an issue.

I'd like to use the src/ dir (i.e., TS) vs. dist/ (i.e., JS) when using the package within the monorepo via the workspace: protocol. Essentially, I want to be able to define a different config when not published, relying on pnpm's publishConfig to do the overrides when I publish to the npm registry:

    "publishConfig": {
        "type": "module",
        "exports": {
            ".": {
                "types": "./dist/index.d.ts",
                "require": "./dist/index.js",
                "import": "./dist/index.mjs"
            }
        },
        "main": "./dist/index.js",
        "module": "./dist/index.mjs",
        "types": "./dist/index.d.ts"
    },
    "main": "./src/index.ts",

Maybe there is a better way to do what I'm after, or maybe this is a feature that could be made to work with unbuild: if publishConfig is present in package.json, override things before using the bast config in package.json to define the build.

Additional information

  • Would you be willing to help implement this feature?

Maybe this would mean teaching

export function inferEntries(
to look for publishConfig and the list of keys it can override?