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