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 sourceRoot: './',
29 noEmit: false,
30 declaration: true,
31 declarationDir: './dist/types/',
32 target: 'esnext',
33 },
34 }),
35
36 flowTypings(),
37
38 buble({
39 transforms: {
40 unicodeRegExp: false,
41 defaultParameter: false,
42 dangerousForOf: true,
43 dangerousTaggedTemplateString: true,
44 destructuring: false,
45 asyncAwait: false,
46 arrow: false,
47 classes: false,
48 computedProperty: false,
49 conciseMethodProperty: false,
50 templateString: false,
51 objectRestSpread: false,
52 parameterDestructuring: false,
53 spreadRest: false,
54 },
55 exclude: 'node_modules/**',
56 }),
57
58 terser({
59 warnings: true,
60 ecma: 2015,
61 keep_fnames: true,
62 ie8: false,
63 compress: {
64 pure_getters: true,
65 toplevel: true,
66 booleans_as_integers: false,
67 keep_fnames: true,
68 keep_fargs: true,
69 if_return: false,
70 ie8: false,
71 sequences: false,
72 loops: false,
73 conditionals: false,
74 join_vars: false,
75 },
76 mangle: {
77 module: true,
78 keep_fnames: true,
79 },
80 output: {
81 beautify: true,
82 braces: true,
83 indent_level: 2,
84 },
85 }),
86];
87
88const output = format => {
89 const extension = format === 'esm' ? '.mjs' : '.js';
90 return {
91 chunkFileNames: '[hash]' + extension,
92 entryFileNames: '[name]' + extension,
93 dir: './dist',
94 exports: 'named',
95 sourcemap: true,
96 indent: false,
97 freeze: false,
98 strict: false,
99 format,
100 // NOTE: All below settings are important for cjs-module-lexer to detect the export
101 // When this changes (and terser mangles the output) this will interfere with Node.js ESM intercompatibility
102 esModule: format !== 'esm',
103 externalLiveBindings: format !== 'esm',
104 generatedCode: {
105 preset: 'es5',
106 reservedNamesAsProps: false,
107 objectShorthand: false,
108 constBindings: false,
109 },
110 };
111};
112
113const config = {
114 input: {
115 wonka: './src/index.ts',
116 },
117 onwarn: () => {},
118 external: () => false,
119 plugins,
120 treeshake: {
121 unknownGlobalSideEffects: false,
122 tryCatchDeoptimization: false,
123 moduleSideEffects: false,
124 },
125 output: [output('esm'), output('cjs')],
126};
127
128export default config;