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