Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add initial Rollup config/scripts

+205 -178
+5 -2
packages/core/package.json
··· 18 18 "formidablelabs", 19 19 "exchanges" 20 20 ], 21 - "main": "dist/urql-core.js", 22 - "module": "dist/urql-core.es.js", 21 + "main": "dist/urql-core.cjs.js", 22 + "module": "dist/urql-core.esm.js", 23 23 "types": "dist/types/index.d.ts", 24 24 "source": "src/index.ts", 25 + "scripts": { 26 + "build": "rollup -c ../../scripts/rollup/config.js" 27 + }, 25 28 "jest": { 26 29 "preset": "../../scripts/jest/preset" 27 30 },
+31 -176
scripts/rollup/config.js
··· 1 - import { DEFAULT_EXTENSIONS } from '@babel/core'; 2 - import commonjs from '@rollup/plugin-commonjs'; 3 - import nodeResolve from '@rollup/plugin-node-resolve'; 4 - import typescript from 'rollup-plugin-typescript2'; 5 - import buble from '@rollup/plugin-buble'; 6 - import babel from 'rollup-plugin-babel'; 7 - import replace from 'rollup-plugin-replace'; 8 - import { terser } from 'rollup-plugin-terser'; 9 - import transformPipe from './scripts/transform-pipe'; 10 - 11 - const pkgInfo = require('./package.json'); 12 - 13 - let external = ['dns', 'fs', 'path', 'url']; 14 - if (pkgInfo.peerDependencies) 15 - external.push(...Object.keys(pkgInfo.peerDependencies)); 16 - if (pkgInfo.dependencies) 17 - external.push(...Object.keys(pkgInfo.dependencies)); 1 + import { makePlugins } from './plugins'; 2 + import * as settings from './settings'; 18 3 19 - const externalPredicate = new RegExp(`^(${external.join('|')})($|/)`); 20 - const externalTest = id => { 21 - if (id === 'babel-plugin-transform-async-to-promises/helpers') { 22 - return false; 23 - } 24 - 25 - return externalPredicate.test(id); 4 + const input = { 5 + [settings.name]: settings.source, 26 6 }; 27 7 28 - const terserPretty = terser({ 29 - sourcemap: true, 30 - warnings: true, 31 - ecma: 5, 32 - keep_fnames: true, 33 - ie8: false, 34 - compress: { 35 - pure_getters: true, 36 - toplevel: true, 37 - booleans_as_integers: false, 38 - keep_fnames: true, 39 - keep_fargs: true, 40 - if_return: false, 41 - ie8: false, 42 - sequences: false, 43 - loops: false, 44 - conditionals: false, 45 - join_vars: false 46 - }, 47 - mangle: false, 48 - output: { 49 - beautify: true, 50 - braces: true, 51 - indent_level: 2 8 + const config = { 9 + input, 10 + external: settings.isExternal, 11 + treeshake: { 12 + unknownGlobalSideEffects: false, 13 + tryCatchDeoptimization: false, 14 + moduleSideEffects: false 52 15 } 53 - }); 16 + }; 54 17 55 - const terserMinified = terser({ 18 + const output = (format = 'cjs', ext = '.js') => ({ 19 + chunkFileNames: '[name]-[hash].[format]' + ext, 20 + entryFileNames: '[name].[format]' + ext, 21 + dir: './dist', 22 + exports: 'named', 23 + externalLiveBindings: false, 56 24 sourcemap: true, 57 - warnings: true, 58 - ecma: 5, 59 - ie8: false, 60 - toplevel: true, 61 - compress: { 62 - keep_infinity: true, 63 - pure_getters: true, 64 - passes: 10 65 - }, 66 - output: { 67 - comments: false 68 - } 69 - }); 70 - 71 - const makePlugins = (isProduction = false, outputFolder) => [ 72 - nodeResolve({ 73 - mainFields: ['module', 'jsnext', 'main'], 74 - browser: true 75 - }), 76 - commonjs({ 77 - ignoreGlobal: true, 78 - include: /\/node_modules\//, 79 - namedExports: { 80 - 'react': Object.keys(require('react')), 81 - 'node_modules/scheduler/index.js': Object.keys(require('scheduler')), 82 - }, 83 - }), 84 - typescript({ 85 - useTsconfigDeclarationDir: true, 86 - tsconfigDefaults: { 87 - compilerOptions: { 88 - sourceMap: true 89 - }, 90 - }, 91 - tsconfigOverride: { 92 - exclude: [ 93 - 'src/**/*.test.ts', 94 - 'src/**/*.test.tsx', 95 - 'src/**/test-utils/*' 96 - ], 97 - compilerOptions: { 98 - declaration: !isProduction, 99 - declarationDir: `${outputFolder}/types/`, 100 - target: 'es6', 101 - }, 102 - }, 103 - }), 104 - buble({ 105 - transforms: { 106 - unicodeRegExp: false, 107 - dangerousForOf: true, 108 - dangerousTaggedTemplateString: true 109 - }, 110 - objectAssign: 'Object.assign', 111 - exclude: 'node_modules/**' 112 - }), 113 - babel({ 114 - babelrc: false, 115 - extensions: [...DEFAULT_EXTENSIONS, 'ts', 'tsx'], 116 - exclude: 'node_modules/**', 117 - presets: [], 118 - plugins: [ 119 - transformPipe, 120 - 'babel-plugin-closure-elimination', 121 - '@babel/plugin-transform-object-assign', 122 - ['@babel/plugin-transform-react-jsx', { 123 - pragma: 'React.createElement', 124 - pragmaFrag: 'React.Fragment', 125 - useBuiltIns: true 126 - }], 127 - ['babel-plugin-transform-async-to-promises', { 128 - inlineHelpers: true, 129 - externalHelpers: true 130 - }] 131 - ] 132 - }), 133 - isProduction && replace({ 134 - 'process.env.NODE_ENV': JSON.stringify('production') 135 - }), 136 - isProduction ? terserMinified : terserPretty 137 - ].filter(Boolean); 138 - 139 - const makeConfig = () => ({ 140 - input: { 141 - core: './src/client.ts', 142 - urql: './src/index.ts' 143 - }, 144 - external: externalTest, 145 - treeshake: { 146 - propertyReadSideEffects: false 147 - } 25 + esModule: false, 26 + indent: false, 27 + freeze: false, 28 + strict: false, 29 + format, 148 30 }); 149 31 150 32 export default [ 151 33 { 152 - ...makeConfig(), 153 - plugins: makePlugins(false, './dist'), 34 + ...config, 35 + plugins: makePlugins({ isProduction: false }), 154 36 output: [ 155 - { 156 - sourcemap: true, 157 - legacy: true, 158 - freeze: false, 159 - esModule: false, 160 - dir: './dist/cjs', 161 - format: 'cjs', 162 - }, 163 - { 164 - sourcemap: true, 165 - legacy: true, 166 - freeze: false, 167 - esModule: false, 168 - dir: './dist/es', 169 - format: 'esm', 170 - }, 37 + output('cjs', '.js'), 38 + output('esm', '.js'), 171 39 ], 172 40 }, 173 41 { 174 - ...makeConfig(), 175 - plugins: makePlugins(true, './dist'), 176 - onwarn: () => {}, 42 + ...config, 43 + plugins: makePlugins({ isProduction: true }), 177 44 output: [ 178 - { 179 - sourcemap: false, 180 - legacy: true, 181 - freeze: false, 182 - dir: './dist/cjs/min', 183 - format: 'cjs', 184 - }, 185 - { 186 - sourcemap: false, 187 - legacy: true, 188 - freeze: false, 189 - dir: './dist/es/min', 190 - format: 'esm', 191 - }, 45 + output('cjs', '.min.js'), 46 + output('esm', '.min.js'), 192 47 ], 193 48 }, 194 49 ];
+138
scripts/rollup/plugins.js
··· 1 + import { DEFAULT_EXTENSIONS } from '@babel/core'; 2 + import commonjs from '@rollup/plugin-commonjs'; 3 + import nodeResolve from '@rollup/plugin-node-resolve'; 4 + import typescript from 'rollup-plugin-typescript2'; 5 + import buble from '@rollup/plugin-buble'; 6 + import replace from '@rollup/plugin-replace'; 7 + import babel from 'rollup-plugin-babel'; 8 + import compiler from '@ampproject/rollup-plugin-closure-compiler'; 9 + import { terser } from 'rollup-plugin-terser'; 10 + 11 + import babelPluginTransformPipe from '../babel/transform-pipe'; 12 + import babelPluginTransformInvariant from '../babel/transform-invariant-warning'; 13 + 14 + import * as settings from './settings'; 15 + 16 + export const makePlugins = ({ isProduction } = {}) => [ 17 + nodeResolve({ 18 + dedupe: settings.externalModules, 19 + mainFields: ['module', 'jsnext', 'main'], 20 + preferBuiltins: false, 21 + browser: true 22 + }), 23 + commonjs({ 24 + ignoreGlobal: true, 25 + include: /\/node_modules\//, 26 + namedExports: settings.hasReact ? { 27 + react: Object.keys(require('react')) 28 + } : {}, 29 + }), 30 + typescript({ 31 + useTsconfigDeclarationDir: true, 32 + objectHashIgnoreUnknownHack: true, 33 + tsconfigDefaults: { 34 + compilerOptions: { 35 + sourceMap: true 36 + }, 37 + }, 38 + tsconfigOverride: { 39 + exclude: [ 40 + 'src/**/*.test.ts', 41 + 'src/**/*.test.tsx', 42 + 'src/**/test-utils/*' 43 + ], 44 + compilerOptions: { 45 + declaration: !isProduction, 46 + declarationDir: './dist/types', 47 + target: 'es6', 48 + }, 49 + }, 50 + }), 51 + buble({ 52 + transforms: { 53 + unicodeRegExp: false, 54 + dangerousForOf: true, 55 + dangerousTaggedTemplateString: true 56 + }, 57 + objectAssign: 'Object.assign', 58 + exclude: 'node_modules/**' 59 + }), 60 + babel({ 61 + babelrc: false, 62 + extensions: [...DEFAULT_EXTENSIONS, 'ts', 'tsx'], 63 + exclude: 'node_modules/**', 64 + presets: [], 65 + plugins: [ 66 + babelPluginTransformPipe, 67 + babelPluginTransformInvariant, 68 + 'babel-plugin-closure-elimination', 69 + '@babel/plugin-transform-object-assign', 70 + settings.hasReact && ['@babel/plugin-transform-react-jsx', { 71 + pragma: 'React.createElement', 72 + pragmaFrag: 'React.Fragment', 73 + useBuiltIns: true 74 + }], 75 + settings.hasPreact && ['@babel/plugin-transform-react-jsx', { 76 + pragma: 'h', 77 + useBuiltIns: true 78 + }], 79 + ['babel-plugin-transform-async-to-promises', { 80 + inlineHelpers: true, 81 + externalHelpers: true 82 + }] 83 + ].filter(Boolean) 84 + }), 85 + isProduction && replace({ 86 + 'process.env.NODE_ENV': JSON.stringify('production') 87 + }), 88 + compiler({ 89 + formatting: 'PRETTY_PRINT', 90 + compilation_level: 'SIMPLE_OPTIMIZATIONS' 91 + }), 92 + isProduction ? terserMinified : terserPretty 93 + ].filter(Boolean); 94 + 95 + const terserPretty = terser({ 96 + sourcemap: true, 97 + warnings: true, 98 + ecma: 5, 99 + keep_fnames: true, 100 + ie8: false, 101 + compress: { 102 + pure_getters: true, 103 + toplevel: true, 104 + booleans_as_integers: false, 105 + keep_fnames: true, 106 + keep_fargs: true, 107 + if_return: false, 108 + ie8: false, 109 + sequences: false, 110 + loops: false, 111 + conditionals: false, 112 + join_vars: false 113 + }, 114 + mangle: false, 115 + output: { 116 + beautify: true, 117 + braces: true, 118 + indent_level: 2 119 + } 120 + }); 121 + 122 + const terserMinified = terser({ 123 + sourcemap: true, 124 + warnings: true, 125 + ecma: 5, 126 + ie8: false, 127 + toplevel: true, 128 + compress: { 129 + keep_infinity: true, 130 + pure_getters: true, 131 + passes: 10 132 + }, 133 + output: { 134 + comments: false 135 + } 136 + }); 137 + 138 +
+31
scripts/rollup/settings.js
··· 1 + const path = require('path'); 2 + const cwd = process.cwd(); 3 + 4 + const pkg = require(path.resolve(cwd, './package.json')); 5 + 6 + export const name = pkg.name 7 + .replace(/[@\s\/]+/g, ' ') 8 + .trim() 9 + .replace(/\s+/, '-') 10 + .toLowerCase(); 11 + 12 + export const source = pkg.source || './src/index.ts'; 13 + 14 + export const externalModules = ['dns', 'fs', 'path', 'url']; 15 + if (pkg.peerDependencies) 16 + externalModules.push(...Object.keys(pkg.peerDependencies)); 17 + if (pkg.dependencies) 18 + externalModules.push(...Object.keys(pkg.dependencies)); 19 + 20 + const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`); 21 + 22 + export const isExternal = id => { 23 + if (id === 'babel-plugin-transform-async-to-promises/helpers') { 24 + return false; 25 + } 26 + 27 + return externalPredicate.test(id); 28 + }; 29 + 30 + export const hasReact = externalModules.includes('react'); 31 + export const hasPreact = externalModules.includes('preact');