diff --git a/packages/gatsby/cache-dir/static-entry.js b/packages/gatsby/cache-dir/static-entry.js index 015a8222711e1..444130500a548 100644 --- a/packages/gatsby/cache-dir/static-entry.js +++ b/packages/gatsby/cache-dir/static-entry.js @@ -1,8 +1,9 @@ const React = require(`react`) const fs = require(`fs`) +const { join } = require(`path`) const { renderToString, renderToStaticMarkup } = require(`react-dom/server`) const { StaticRouter, Route, withRouter } = require(`react-router-dom`) -const { kebabCase, get, merge, isArray, isString, flatten } = require(`lodash`) +const { kebabCase, get, merge, isString, flatten } = require(`lodash`) const apiRunner = require(`./api-runner-ssr`) const pages = require(`./pages.json`) @@ -40,6 +41,13 @@ try { Html = Html && Html.__esModule ? Html.default : Html +function urlJoin(...parts) { + return parts.reduce((r, next) => { + const segment = next == null ? `` : String(next).replace(/^\/+/, ``) + return segment ? `${r.replace(/\/$/, ``)}/${segment}` : r + }, ``) +} + const pathChunkName = path => { const name = path === `/` ? `index` : kebabCase(path) return `path---${name}` @@ -177,14 +185,14 @@ export default (locals, callback) => { return null } - return chunks.map(c => { - if (c === `/`) { + return chunks.map(chunk => { + if (chunk === `/`) { return null } - if (c.slice(0, 15) === `webpack-runtime`) { + if (chunk.slice(0, 15) === `webpack-runtime`) { return null } - return `${pathPrefix}${c}` + return chunk }) }) ).filter(s => isString(s)) @@ -192,7 +200,7 @@ export default (locals, callback) => { const styles = scriptsAndStyles.filter(s => s.endsWith(`.css`)) const runtimeRaw = fs.readFileSync( - `${process.cwd()}/public/${runtimeScript}`, + join(process.cwd(), `public`, runtimeScript), `utf-8` ) postBodyComponents.push( @@ -211,7 +219,12 @@ export default (locals, callback) => { .forEach(script => { // Add preload s for scripts. headComponents.unshift( - + ) }) @@ -223,10 +236,10 @@ export default (locals, callback) => { headComponents.unshift(