unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

cannot build to cjs using mkdist

Open Barbapapazes opened this issue 2 years ago • 3 comments

Hello,

I was experimenting with unbuild and I encounter an issue.

Is it possible (if recommanded) to build to esm and cjs at the same time using mkdist like with rollup?

Barbapapazes avatar Sep 06 '23 14:09 Barbapapazes

I expect to have

    ├── vite.cjs
    ├── vite.d.cts
    ├── vite.d.mts
    ├── vite.d.ts
    ├── vite.mjs
    ├── webpack.cjs
    ├── webpack.d.cts
    ├── webpack.d.mts
    ├── webpack.d.ts
    └── webpack.mjs

but I only got

├── vite.d.ts
├── vite.mjs
├── webpack.d.ts
└── webpack.mjs

Barbapapazes avatar Sep 17 '23 17:09 Barbapapazes

Here was my work around for now, just a snippet I use in most the configs:

function dualOutput(
  config: Omit<MkdistBuildEntry, "builder" | "format">
): BuildEntry[] {
  return [
    {
      builder: "mkdist",
      format: "esm",
      ...config,
      pattern: "**/!(*.stories).{js,jsx,ts,tsx}",
    },
    {
      builder: "mkdist",
      format: "cjs",
      ...config,
      pattern: "**/!(*.stories).{js,jsx,ts,tsx}",
    },
  ];
}
export default defineBuildConfig({
  entries: [
    "./src/index",
    ...dualOutput({
      input: "./src/components/Bits/",
      outDir: "./dist/bits",
    }),

joshmeads avatar Sep 25 '23 23:09 joshmeads

Here was my work around for now, just a snippet I use in most the configs:

function dualOutput(
  config: Omit<MkdistBuildEntry, "builder" | "format">
): BuildEntry[] {
  return [
    {
      builder: "mkdist",
      format: "esm",
      ...config,
      pattern: "**/!(*.stories).{js,jsx,ts,tsx}",
    },
    {
      builder: "mkdist",
      format: "cjs",
      ...config,
      pattern: "**/!(*.stories).{js,jsx,ts,tsx}",
    },
  ];
}
export default defineBuildConfig({
  entries: [
    "./src/index",
    ...dualOutput({
      input: "./src/components/Bits/",
      outDir: "./dist/bits",
    }),

Yeah, I'm also using this way but, since there is a way to generate both with the rollup preset, I was hoping to do the same way for mkdist!

Barbapapazes avatar Sep 26 '23 20:09 Barbapapazes

Moving docs to https://github.com/unjs/unbuild/issues/398

pi0 avatar Jun 04 '24 22:06 pi0