Merge branch 'master' into combined-prs-branch
[poolifier.git] / rollup.config.mjs
index 8f1f26562a4817d75a018129b3a09f76fd9129ab..26739f65d88ca4d12f75c24425ac19ef3dedcbda 100644 (file)
@@ -24,6 +24,7 @@ const availableParallelism = () => {
 const isDevelopmentBuild = env.BUILD === 'development'
 const isAnalyzeBuild = env.ANALYZE
 const isDocumentationBuild = env.DOCUMENTATION
+const sourcemap = env.SOURCEMAP !== 'false'
 
 const maxWorkers = Math.floor(availableParallelism() / 2)
 
@@ -36,21 +37,23 @@ export default defineConfig([
         format: 'cjs',
         ...(isDevelopmentBuild && {
           dir: './lib',
-          sourcemap: true,
+          entryFileNames: '[name].cjs',
+          chunkFileNames: '[name]-[hash].cjs',
           preserveModules: true,
           preserveModulesRoot: './src'
         }),
         ...(!isDevelopmentBuild && {
-          file: './lib/index.js',
-          sourcemap: true,
+          file: './lib/index.cjs',
           plugins: [terser({ maxWorkers })]
+        }),
+        ...(sourcemap && {
+          sourcemap
         })
       },
       {
         format: 'esm',
         ...(isDevelopmentBuild && {
           dir: './lib',
-          sourcemap: true,
           entryFileNames: '[name].mjs',
           chunkFileNames: '[name]-[hash].mjs',
           preserveModules: true,
@@ -58,49 +61,39 @@ export default defineConfig([
         }),
         ...(!isDevelopmentBuild && {
           file: './lib/index.mjs',
-          sourcemap: true,
           plugins: [terser({ maxWorkers })]
+        }),
+        ...(sourcemap && {
+          sourcemap
         })
       }
     ],
-    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: './tsconfig.build.json'
+        tsconfig: './tsconfig.build.json',
+        compilerOptions: {
+          sourceMap: sourcemap
+        }
       }),
       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()
     ]
   }
 ])