Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
at main 802 B view raw
1import { silent as resolveFrom } from 'resolve-from'; 2 3const NODE_MODULES_JS_RE = /node_modules[/\\].*\.js$/; 4const REACT_STATIC_RE = /node_modules[/\\]react-static/; 5 6export default () => ({ 7 webpack: (config, { stage }) => { 8 if (stage === 'node') { 9 config.externals = [ 10 ...config.externals, 11 (context, request, callback) => { 12 if (/^[./]/.test(request)) { 13 return callback(); 14 } 15 16 const res = resolveFrom(`${context}/`, request); 17 if ( 18 res && 19 NODE_MODULES_JS_RE.test(res) && 20 !REACT_STATIC_RE.test(res) 21 ) { 22 return callback(null, `commonjs ${request}`); 23 } else { 24 return callback(); 25 } 26 }, 27 ]; 28 } 29 30 return config; 31 }, 32});