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