feat: bundle TS types definition into one file
[poolifier.git] / rollup.config.mjs
index 90d56e6034a53764bc90c4ccc8e744a5d21c44a6..fd0452ecda4ec28eef891149ba07bae2c730a2a8 100644 (file)
@@ -1,4 +1,5 @@
 import * as os from 'node:os'
+import { dts } from 'rollup-plugin-dts'
 import terser from '@rollup/plugin-terser'
 import typescript from '@rollup/plugin-typescript'
 import analyze from 'rollup-plugin-analyzer'
@@ -24,58 +25,78 @@ const isDocumentationBuild = process.env.DOCUMENTATION
 
 const maxWorkers = Math.floor(availableParallelism() / 2)
 
-export default {
-  input: 'src/index.ts',
-  strictDeprecations: true,
-  output: [
-    {
-      format: 'cjs',
-      ...(isDevelopmentBuild && {
-        dir: 'lib',
-        sourcemap: true,
-        preserveModules: true,
-        preserveModulesRoot: 'src'
+export default [
+  {
+    input: 'src/index.ts',
+    strictDeprecations: true,
+    output: [
+      {
+        format: 'cjs',
+        ...(isDevelopmentBuild && {
+          dir: 'lib',
+          sourcemap: true,
+          preserveModules: true,
+          preserveModulesRoot: 'src'
+        }),
+        ...(!isDevelopmentBuild && {
+          file: 'lib/index.js',
+          plugins: [terser({ maxWorkers })]
+        })
+      },
+      {
+        format: 'esm',
+        ...(isDevelopmentBuild && {
+          dir: 'lib',
+          sourcemap: true,
+          entryFileNames: '[name].mjs',
+          preserveModules: true,
+          preserveModulesRoot: 'src'
+        }),
+        ...(!isDevelopmentBuild && {
+          file: 'lib/index.mjs',
+          plugins: [terser({ maxWorkers })]
+        })
+      }
+    ],
+    external: [
+      'node:async_hooks',
+      'node:cluster',
+      'node:crypto',
+      'node:events',
+      'node:fs',
+      'node:os',
+      'node:perf_hooks',
+      'node:worker_threads'
+    ],
+    plugins: [
+      typescript({
+        tsconfig: isDevelopmentBuild
+          ? 'tsconfig.development.json'
+          : 'tsconfig.production.json'
       }),
-      ...(!isDevelopmentBuild && {
-        file: 'lib/index.js',
-        plugins: [terser({ maxWorkers })]
-      })
-    },
-    {
-      format: 'esm',
-      ...(isDevelopmentBuild && {
-        dir: 'lib',
-        sourcemap: true,
-        entryFileNames: '[name].mjs',
-        preserveModules: true,
-        preserveModulesRoot: 'src'
+      del({
+        targets: ['lib/*']
       }),
-      ...(!isDevelopmentBuild && {
-        file: 'lib/index.mjs',
-        plugins: [terser({ maxWorkers })]
+      isAnalyzeBuild && analyze(),
+      isDocumentationBuild && command('pnpm typedoc')
+    ]
+  },
+  {
+    input: './lib/dts/index.d.ts',
+    output: [{ format: 'esm', file: 'lib/index.d.ts' }],
+    external: [
+      'node:async_hooks',
+      'node:cluster',
+      'node:events',
+      'node:perf_hooks',
+      'node:worker_threads'
+    ],
+    plugins: [
+      dts(),
+      del({
+        targets: ['lib/dts'],
+        hook: 'buildEnd'
       })
-    }
-  ],
-  external: [
-    'node:async_hooks',
-    'node:cluster',
-    'node:crypto',
-    'node:events',
-    'node:fs',
-    'node:os',
-    'node:perf_hooks',
-    'node:worker_threads'
-  ],
-  plugins: [
-    typescript({
-      tsconfig: isDevelopmentBuild
-        ? 'tsconfig.development.json'
-        : 'tsconfig.production.json'
-    }),
-    del({
-      targets: ['lib/*']
-    }),
-    isAnalyzeBuild && analyze(),
-    isDocumentationBuild && command('pnpm typedoc')
-  ]
-}
+    ]
+  }
+]