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