Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.
1import * as path from 'path';
2
3import resolve from '@rollup/plugin-node-resolve';
4import { babel } from '@rollup/plugin-babel';
5import { terser } from 'rollup-plugin-terser';
6
7const cwd = process.cwd();
8const externalModules = ['dns', 'fs', 'path', 'url'];
9const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`);
10
11const config = {
12 input: {
13 graphql: './alias/index.mjs',
14 },
15 external(id) {
16 return externalPredicate.test(id);
17 },
18 treeshake: {
19 unknownGlobalSideEffects: false,
20 tryCatchDeoptimization: false,
21 moduleSideEffects: false,
22 },
23};
24
25export default {
26 ...config,
27 shimMissingExports: true,
28 plugins: [
29 {
30 async resolveId(source, importer) {
31 if (source.startsWith('.') && importer) {
32 source = path.resolve(path.dirname(importer), source);
33 }
34
35 const base = path.join(cwd, 'node_modules/graphql/');
36 const baseSource = path.relative(base, source);
37 if (baseSource.startsWith('..')) {
38 return null;
39 }
40
41 const aliasSource = path.join(cwd, 'alias/', baseSource);
42 return this.resolve(aliasSource, importer, { skipSelf: true });
43 },
44 },
45
46 resolve({
47 extensions: ['.mjs', '.js'],
48 mainFields: ['module', 'browser', 'main'],
49 preferBuiltins: false,
50 browser: true,
51 }),
52
53 babel({
54 babelrc: false,
55 babelHelpers: 'bundled',
56 presets: [],
57 plugins: [
58 'babel-plugin-modular-graphql',
59 'reghex/babel',
60 ],
61 }),
62 ],
63
64 output: [
65 {
66 chunkFileNames: '[hash].mjs',
67 entryFileNames: '[name].mjs',
68 dir: './dist',
69 exports: 'named',
70 externalLiveBindings: false,
71 sourcemap: true,
72 esModule: false,
73 indent: false,
74 freeze: false,
75 strict: false,
76 format: 'esm',
77 },
78 {
79 chunkFileNames: '[hash].min.mjs',
80 entryFileNames: '[name].min.mjs',
81 dir: './dist',
82 exports: 'named',
83 externalLiveBindings: false,
84 sourcemap: true,
85 esModule: false,
86 indent: false,
87 freeze: false,
88 strict: false,
89 format: 'esm',
90 plugins: [
91 terser({
92 warnings: true,
93 ecma: 5,
94 ie8: false,
95 toplevel: true,
96 compress: {
97 keep_infinity: true,
98 pure_getters: true,
99 passes: 10
100 },
101 mangle: {
102 module: true,
103 },
104 output: {
105 comments: false
106 }
107 }),
108 ],
109 }
110 ],
111};