Merge branch 'master' of github.com:poolifier/poolifier
[poolifier.git] / rollup.config.mjs
index 9e8cd65bb0317152141a539de08f8d64c16a2c6c..e3af7e1d8af9657fe50be3750b7aa4acd8671a25 100644 (file)
@@ -1,4 +1,5 @@
 import * as os from 'node:os'
+import { env } from 'node:process'
 import { dts } from 'rollup-plugin-dts'
 import terser from '@rollup/plugin-terser'
 import typescript from '@rollup/plugin-typescript'
@@ -20,9 +21,9 @@ const availableParallelism = () => {
   return availableParallelism
 }
 
-const isDevelopmentBuild = process.env.BUILD === 'development'
-const isAnalyzeBuild = process.env.ANALYZE
-const isDocumentationBuild = process.env.DOCUMENTATION
+const isDevelopmentBuild = env.BUILD === 'development'
+const isAnalyzeBuild = env.ANALYZE
+const isDocumentationBuild = env.DOCUMENTATION
 
 const maxWorkers = Math.floor(availableParallelism() / 2)
 
@@ -33,9 +34,9 @@ export default defineConfig([
     output: [
       {
         format: 'cjs',
+        sourcemap: true,
         ...(isDevelopmentBuild && {
           dir: './lib',
-          sourcemap: true,
           preserveModules: true,
           preserveModulesRoot: './src'
         }),
@@ -46,9 +47,9 @@ export default defineConfig([
       },
       {
         format: 'esm',
+        sourcemap: true,
         ...(isDevelopmentBuild && {
           dir: './lib',
-          sourcemap: true,
           entryFileNames: '[name].mjs',
           chunkFileNames: '[name]-[hash].mjs',
           preserveModules: true,
@@ -60,46 +61,32 @@ export default defineConfig([
         })
       }
     ],
-    external: [
-      'node:async_hooks',
-      'node:cluster',
-      'node:crypto',
-      'node:events',
-      'node:fs',
-      'node:os',
-      'node:perf_hooks',
-      'node:worker_threads'
-    ],
+    external: [/^node:*/],
     plugins: [
       typescript({
-        tsconfig: isDevelopmentBuild
-          ? './tsconfig.development.json'
-          : './tsconfig.production.json'
+        tsconfig: './tsconfig.build.json',
+        compilerOptions: {
+          sourceMap: true
+        }
       }),
       del({
         targets: ['./lib/*']
       }),
-      isAnalyzeBuild && analyze(),
-      isDocumentationBuild && command('pnpm typedoc')
+      Boolean(isAnalyzeBuild) && analyze(),
+      Boolean(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'
-    ],
+    external: [/^node:*/],
     plugins: [
       dts(),
       del({
         targets: ['./lib/dts'],
         hook: 'buildEnd'
       }),
-      isAnalyzeBuild && analyze()
+      Boolean(isAnalyzeBuild) && analyze()
     ]
   }
 ])