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