1import commonjs from '@rollup/plugin-commonjs';
2import resolve from '@rollup/plugin-node-resolve';
3import typescript from '@rollup/plugin-typescript';
4import buble from '@rollup/plugin-buble';
5import { terser } from 'rollup-plugin-terser';
6
7import flowTypings from './scripts/flow-typings-plugin';
8
9const plugins = [
10 resolve({
11 extensions: ['.mjs', '.js', '.ts'],
12 mainFields: ['module', 'jsnext', 'main'],
13 preferBuiltins: false,
14 browser: true,
15 }),
16
17 commonjs({
18 ignoreGlobal: true,
19 include: /\/node_modules\//,
20 extensions: ['.mjs', '.js', '.ts'],
21 }),
22
23 typescript({
24 typescript: require('typescript'),
25 exclude: ['src/**/*.test.ts', '**/__tests__/*'],
26 compilerOptions: {
27 sourceMap: true,
28 noEmit: false,
29 declaration: true,
30 declarationDir: './dist/types/',
31 target: 'esnext',
32 },
33 }),
34
35 flowTypings(),
36
37 buble({
38 transforms: {
39 unicodeRegExp: false,
40 dangerousForOf: true,
41 dangerousTaggedTemplateString: true,
42 asyncAwait: false,
43 arrow: false,
44 classes: false,
45 conciseMethodProperty: false,
46 templateString: false,
47 objectRestSpread: false,
48 },
49 exclude: 'node_modules/**',
50 }),
51
52 terser({
53 warnings: true,
54 ecma: 2015,
55 keep_fnames: true,
56 ie8: false,
57 compress: {
58 pure_getters: true,
59 toplevel: true,
60 booleans_as_integers: false,
61 keep_fnames: true,
62 keep_fargs: true,
63 if_return: false,
64 ie8: false,
65 sequences: false,
66 loops: false,
67 conditionals: false,
68 join_vars: false,
69 },
70 mangle: {
71 module: true,
72 keep_fnames: true,
73 },
74 output: {
75 beautify: true,
76 braces: true,
77 indent_level: 2,
78 },
79 }),
80];
81
82const output = format => {
83 const extension = format === 'esm' ? '.mjs' : '.js';
84 return {
85 chunkFileNames: '[hash]' + extension,
86 entryFileNames: '[name]' + extension,
87 dir: './dist',
88 exports: 'named',
89 sourcemap: true,
90 indent: false,
91 freeze: false,
92 strict: false,
93 format,
94 // NOTE: All below settings are important for cjs-module-lexer to detect the export
95 // When this changes (and terser mangles the output) this will interfere with Node.js ESM intercompatibility
96 esModule: format !== 'esm',
97 externalLiveBindings: format !== 'esm',
98 generatedCode: {
99 preset: 'es5',
100 reservedNamesAsProps: false,
101 objectShorthand: false,
102 constBindings: false,
103 },
104 };
105};
106
107const config = {
108 input: {
109 wonka: './src/index.ts',
110 },
111 onwarn: () => {},
112 external: () => false,
113 plugins,
114 treeshake: {
115 unknownGlobalSideEffects: false,
116 tryCatchDeoptimization: false,
117 moduleSideEffects: false,
118 },
119 output: [output('esm'), output('cjs')],
120};
121
122export default config;