Build system: add bundling analysis to dev build (#150)
[poolifier.git] / rollup.config.mjs
index d35b8c42a00cea7e12e5eaf36f5d1733d048a374..8afbc006de8827bccd162a14d2d3a1d4e33de695 100644 (file)
@@ -1,17 +1,27 @@
 import typescript from 'rollup-plugin-typescript2'
+import analyze from 'rollup-plugin-analyzer'
+import { terser } from 'rollup-plugin-terser'
 import del from 'rollup-plugin-delete'
 
 const isDevelopmentBuild = process.env.BUILD === 'development'
 
 export default {
   input: 'src/index.ts',
-  output: {
-    dir: 'lib',
-    format: 'cjs',
-    sourcemap: !!isDevelopmentBuild,
-    preserveModules: true,
-    preserveModulesRoot: 'src'
-  },
+  output: [
+    {
+      dir: 'lib',
+      format: 'cjs',
+      sourcemap: !!isDevelopmentBuild,
+      preserveModules: true,
+      preserveModulesRoot: 'src'
+    },
+    isDevelopmentBuild && {
+      file: 'lib.min/index.js',
+      format: 'cjs',
+      sourcemap: !!isDevelopmentBuild,
+      plugins: [terser({ numWorkers: 2 })]
+    }
+  ],
   external: ['async_hooks', 'cluster', 'events', 'worker_threads'],
   plugins: [
     typescript({
@@ -20,7 +30,8 @@ export default {
         : 'tsconfig.json'
     }),
     del({
-      targets: 'lib/*'
-    })
+      targets: ['lib/*', 'lib.min/*']
+    }),
+    isDevelopmentBuild && analyze()
   ]
 }