Skip to content

Commit

Permalink
create public page renderer and export correct version (dev / prod) d…
Browse files Browse the repository at this point in the history
…epending on NODE_ENV
  • Loading branch information
pieh committed Jun 22, 2018
1 parent a9ce586 commit f75fe16
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
19 changes: 1 addition & 18 deletions packages/gatsby/src/cache-dir/gatsby-browser-entry.js
Original file line number Diff line number Diff line change
@@ -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({})

Expand Down
23 changes: 23 additions & 0 deletions packages/gatsby/src/cache-dir/public-page-renderer-dev.js
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions packages/gatsby/src/cache-dir/public-page-renderer-prod.js
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions packages/gatsby/src/cache-dir/public-page-renderer.js
Original file line number Diff line number Diff line change
@@ -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`))
}

0 comments on commit f75fe16

Please sign in to comment.