From 0f790b37e31ce7434d1d7f38779a95cb78d4046a Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Tue, 23 Jan 2018 22:38:18 -0800 Subject: [PATCH] moved to fs read --- server/utils/prefetchTags.js | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/server/utils/prefetchTags.js b/server/utils/prefetchTags.js index 4534e84cd..b48720a4b 100644 --- a/server/utils/prefetchTags.js +++ b/server/utils/prefetchTags.js @@ -1,5 +1,7 @@ // @flow import React from 'react'; +import fs from 'fs'; +import path from 'path'; import webpackConfig from '../../webpack.config'; const PUBLIC_PATH = webpackConfig.output.publicPath; @@ -8,26 +10,26 @@ const prefetchTags = [ , ]; -if (process.env.NODE_ENV === 'production') { - try { - const manifest = require('../../dist/manifest.json'); - Object.values(manifest).forEach(filename => { - if (typeof filename !== 'string') return; - if (filename.endsWith('.js')) { - prefetchTags.push( - - ); - } else if (filename.endsWith('.css')) { - prefetchTags.push( - - ); - } - }); - } catch (_e) { - console.warn( - 'Warning: Unable to load dist/manifest.json. Please `yarn build` before starting production server' - ); - } +try { + const manifest = fs.readFileSync( + path.join(__dirname, '../../dist/manifest.json'), + 'utf8' + ); + const manifestData = JSON.parse(manifest); + Object.values(manifestData).forEach(filename => { + if (typeof filename !== 'string') return; + if (filename.endsWith('.js')) { + prefetchTags.push( + + ); + } else if (filename.endsWith('.css')) { + prefetchTags.push( + + ); + } + }); +} catch (_e) { + // no-op } export default prefetchTags;