From d5583041c936733fcbcafeef065330a62c0d3cdb Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 5 Jun 2020 10:33:28 +0200 Subject: [PATCH] allow loader.loadComponent to accept optional key to fetch modules --- packages/gatsby/cache-dir/dev-loader.js | 4 ++-- packages/gatsby/cache-dir/loader.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/gatsby/cache-dir/dev-loader.js b/packages/gatsby/cache-dir/dev-loader.js index a2a3f75a3b6b5..7c69a92c6bbca 100644 --- a/packages/gatsby/cache-dir/dev-loader.js +++ b/packages/gatsby/cache-dir/dev-loader.js @@ -3,8 +3,8 @@ import { findPath } from "./find-path" class DevLoader extends BaseLoader { constructor(syncRequires, matchPaths) { - const loadComponent = chunkName => - Promise.resolve(syncRequires.components[chunkName]) + const loadComponent = (chunkName, key = `components`) => + Promise.resolve(syncRequires[key][chunkName]) super(loadComponent, matchPaths) } diff --git a/packages/gatsby/cache-dir/loader.js b/packages/gatsby/cache-dir/loader.js index 4dc1894c6bda5..bfc8a67aa8919 100644 --- a/packages/gatsby/cache-dir/loader.js +++ b/packages/gatsby/cache-dir/loader.js @@ -360,9 +360,9 @@ const createComponentUrls = componentChunkName => export class ProdLoader extends BaseLoader { constructor(asyncRequires, matchPaths) { - const loadComponent = chunkName => - asyncRequires.components[chunkName] - ? asyncRequires.components[chunkName]() + const loadComponent = (chunkName, key = `components`) => + asyncRequires[key][chunkName] + ? asyncRequires[key][chunkName]() .then(preferDefault) // loader will handle the case when component is null .catch(() => null)