feat: initial work at bundling ESM and CommonJS
[poolifier.git] / rollup.config.mjs
index e1bdac21fe03b621fa5b4e81d2c73b3e2ef5be52..8997445e8f193906422514a30d0c97a837adefa5 100644 (file)
@@ -10,14 +10,30 @@ const isDocumentation = process.env.DOCUMENTATION
 
 export default {
   input: 'src/index.ts',
-  output: {
-    ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }),
-    format: 'cjs',
-    sourcemap: !!isDevelopmentBuild,
-    ...(isDevelopmentBuild && { preserveModules: true }),
-    ...(isDevelopmentBuild && { preserveModulesRoot: 'src' }),
-    ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] })
-  },
+  output: [
+    {
+      ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }),
+      format: 'cjs',
+      sourcemap: !!isDevelopmentBuild,
+      ...(isDevelopmentBuild && {
+        preserveModules: true,
+        preserveModulesRoot: 'src'
+      }),
+      ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] })
+    },
+    {
+      ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.mjs' }),
+      format: 'esm',
+      sourcemap: !!isDevelopmentBuild,
+
+      ...(isDevelopmentBuild && {
+        entryFileNames: '[name].mjs',
+        preserveModules: true,
+        preserveModulesRoot: 'src'
+      }),
+      ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] })
+    }
+  ],
   external: ['async_hooks', 'cluster', 'events', 'os', 'worker_threads'],
   plugins: [
     typescript({