Instrument the code at development build for istanbul (#347)
[poolifier.git] / rollup.config.mjs
1 import typescript from 'rollup-plugin-typescript2'
2 import analyze from 'rollup-plugin-analyzer'
3 import { terser } from 'rollup-plugin-terser'
4 import del from 'rollup-plugin-delete'
5 import command from 'rollup-plugin-command'
6 import istanbul from 'rollup-plugin-istanbul'
7
8 const isDevelopmentBuild = process.env.BUILD === 'development'
9 const isAnalyze = process.env.ANALYZE
10 const isDocumentation = process.env.DOCUMENTATION
11
12 export default {
13 input: 'src/index.ts',
14 output: {
15 ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }),
16 format: 'cjs',
17 sourcemap: !!isDevelopmentBuild,
18 ...(isDevelopmentBuild && { preserveModules: true }),
19 ...(isDevelopmentBuild && { preserveModulesRoot: 'src' }),
20 ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] })
21 },
22 external: ['async_hooks', 'cluster', 'events', 'worker_threads'],
23 plugins: [
24 typescript({
25 tsconfig: isDevelopmentBuild
26 ? 'tsconfig.development.json'
27 : 'tsconfig.json'
28 }),
29 isDevelopmentBuild && istanbul(),
30 del({
31 targets: ['lib/*']
32 }),
33 isAnalyze && analyze(),
34 isDocumentation && command('npm run typedoc')
35 ]
36 }