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';
6import cjsCheck from 'rollup-plugin-cjs-check';
7import dts from 'rollup-plugin-dts';
8
9import flowTypings from './flow-typings-plugin.mjs';
10
11const commonPlugins = [
12 resolve({
13 extensions: ['.mjs', '.js', '.ts'],
14 mainFields: ['module', 'jsnext', 'main'],
15 preferBuiltins: false,
16 browser: true,
17 }),
18
19 commonjs({
20 ignoreGlobal: true,
21 include: /\/node_modules\//,
22 extensions: ['.mjs', '.js', '.ts'],
23 }),
24
25 typescript({
26 exclude: ['src/**/*.test.ts', '**/__tests__/*'],
27 compilerOptions: {
28 sourceMap: true,
29 sourceRoot: './',
30 noEmit: false,
31 declaration: false,
32 target: 'esnext',
33 },
34 }),
35];
36
37const jsPlugins = [
38 ...commonPlugins,
39 cjsCheck(),
40
41 buble({
42 transforms: {
43 unicodeRegExp: false,
44 defaultParameter: false,
45 dangerousForOf: true,
46 dangerousTaggedTemplateString: true,
47 destructuring: false,
48 asyncAwait: false,
49 arrow: false,
50 classes: false,
51 computedProperty: false,
52 conciseMethodProperty: false,
53 templateString: false,
54 objectRestSpread: false,
55 parameterDestructuring: false,
56 spreadRest: false,
57 },
58 exclude: 'node_modules/**',
59 }),
60
61 terser({
62 warnings: true,
63 ecma: 2015,
64 keep_fnames: true,
65 ie8: false,
66 compress: {
67 pure_getters: true,
68 toplevel: true,
69 booleans_as_integers: false,
70 keep_fnames: true,
71 keep_fargs: true,
72 if_return: false,
73 ie8: false,
74 sequences: false,
75 loops: false,
76 conditionals: false,
77 join_vars: false,
78 },
79 mangle: {
80 module: true,
81 keep_fnames: true,
82 },
83 output: {
84 beautify: true,
85 braces: true,
86 indent_level: 2,
87 },
88 }),
89];
90
91const dtsPlugins = [
92 ...commonPlugins,
93 dts(),
94 flowTypings(),
95];
96
97const output = format => {
98 const extension = format === 'esm' ? '.mjs' : '.js';
99 return {
100 chunkFileNames: '[hash]' + extension,
101 entryFileNames: '[name]' + extension,
102 dir: './dist',
103 exports: 'named',
104 sourcemap: true,
105 indent: false,
106 freeze: false,
107 strict: false,
108 format,
109 // NOTE: All below settings are important for cjs-module-lexer to detect the export
110 // When this changes (and terser mangles the output) this will interfere with Node.js ESM intercompatibility
111 esModule: format !== 'esm',
112 externalLiveBindings: format !== 'esm',
113 generatedCode: {
114 preset: 'es5',
115 reservedNamesAsProps: false,
116 objectShorthand: false,
117 constBindings: false,
118 },
119 };
120};
121
122const commonConfig = {
123 input: {
124 wonka: './src/index.ts',
125 },
126 onwarn: () => {},
127 external: () => false,
128 treeshake: {
129 unknownGlobalSideEffects: false,
130 tryCatchDeoptimization: false,
131 moduleSideEffects: false,
132 },
133};
134
135const jsConfig = {
136 ...commonConfig,
137 plugins: jsPlugins,
138 output: [
139 output('esm'),
140 output('cjs'),
141 ],
142};
143
144const dtsConfig = {
145 ...commonConfig,
146 input: {
147 wonka: './src/index.ts',
148 },
149 onwarn: () => {},
150 external: () => false,
151 plugins: dtsPlugins,
152 treeshake: {
153 unknownGlobalSideEffects: false,
154 tryCatchDeoptimization: false,
155 moduleSideEffects: false,
156 },
157 output: {
158 dir: './dist',
159 entryFileNames: '[name].d.ts',
160 format: 'es'
161 },
162};
163
164export default [
165 jsConfig,
166 dtsConfig,
167];