From f75fe16a07b9996c455f122b4b2e3f922aa51ef8 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 22 Jun 2018 13:54:53 +0200 Subject: [PATCH] create public page renderer and export correct version (dev / prod) depending on NODE_ENV --- .../src/cache-dir/gatsby-browser-entry.js | 19 +-------------- .../src/cache-dir/public-page-renderer-dev.js | 23 +++++++++++++++++++ .../cache-dir/public-page-renderer-prod.js | 21 +++++++++++++++++ .../src/cache-dir/public-page-renderer.js | 7 ++++++ 4 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 packages/gatsby/src/cache-dir/public-page-renderer-dev.js create mode 100644 packages/gatsby/src/cache-dir/public-page-renderer-prod.js create mode 100644 packages/gatsby/src/cache-dir/public-page-renderer.js diff --git a/packages/gatsby/src/cache-dir/gatsby-browser-entry.js b/packages/gatsby/src/cache-dir/gatsby-browser-entry.js index f335cd1a03794..8038be8a3e61f 100644 --- a/packages/gatsby/src/cache-dir/gatsby-browser-entry.js +++ b/packages/gatsby/src/cache-dir/gatsby-browser-entry.js @@ -1,24 +1,7 @@ import React from "react" import PropTypes from "prop-types" import Link, { withPrefix, push, replace, navigateTo } from "gatsby-link" -import pages from "./pages.json" -import loader from "./loader" -import JSONStore from "./json-store" - -const PageRenderer = ({ location }) => { - const pageResources = loader.getResourcesForPathname(location.pathname) - return React.createElement(JSONStore, { - pages, - location, - pageResources, - }) -} - -PageRenderer.propTypes = { - location: PropTypes.shape({ - pathname: PropTypes.string.isRequired, - }).isRequired, -} +import PageRenderer from "./public-page-renderer" const StaticQueryContext = React.createContext({}) diff --git a/packages/gatsby/src/cache-dir/public-page-renderer-dev.js b/packages/gatsby/src/cache-dir/public-page-renderer-dev.js new file mode 100644 index 0000000000000..c169409065b3c --- /dev/null +++ b/packages/gatsby/src/cache-dir/public-page-renderer-dev.js @@ -0,0 +1,23 @@ +import React from "react" +import PropTypes from "prop-types" + +import pages from "./pages.json" +import loader from "./loader" +import JSONStore from "./json-store" + +const DevPageRenderer = ({ location }) => { + const pageResources = loader.getResourcesForPathname(location.pathname) + return React.createElement(JSONStore, { + pages, + location, + pageResources, + }) +} + +DevPageRenderer.propTypes = { + location: PropTypes.shape({ + pathname: PropTypes.string.isRequired, + }).isRequired, +} + +export default DevPageRenderer \ No newline at end of file diff --git a/packages/gatsby/src/cache-dir/public-page-renderer-prod.js b/packages/gatsby/src/cache-dir/public-page-renderer-prod.js new file mode 100644 index 0000000000000..82f45afd0c831 --- /dev/null +++ b/packages/gatsby/src/cache-dir/public-page-renderer-prod.js @@ -0,0 +1,21 @@ +import React from "react" +import PropTypes from "prop-types" + +import InternalPageRenderer from "./page-renderer" +import loader from "./loader" + +const ProdPageRenderer = ({ location }) => { + const pageResources = loader.getResourcesForPathname(location.pathname) + return React.createElement(InternalPageRenderer, { + location, + pageResources, + }) +} + +ProdPageRenderer.propTypes = { + location: PropTypes.shape({ + pathname: PropTypes.string.isRequired, + }).isRequired, +} + +export default ProdPageRenderer \ No newline at end of file diff --git a/packages/gatsby/src/cache-dir/public-page-renderer.js b/packages/gatsby/src/cache-dir/public-page-renderer.js new file mode 100644 index 0000000000000..2402fa08d04a6 --- /dev/null +++ b/packages/gatsby/src/cache-dir/public-page-renderer.js @@ -0,0 +1,7 @@ +const preferDefault = m => (m && m.default) || m + +if (process.env.NODE_ENV === `production`) { + module.exports = preferDefault(require(`./public-page-renderer-prod`)) +} else { + module.exports = preferDefault(require(`./public-page-renderer-dev`)) +} \ No newline at end of file