Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(server): fix stats reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Feb 18, 2018
1 parent 5d0262c commit c358e0f
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/server/ssr/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import fs from 'fs'
import chokidar from 'chokidar'

let cache = {}

// NOTE: Razzle could `require` CLIENT_ASSETS_MANIFEST
// In SUIcrux it's currently not possible :(
// Server requires "missing module"
// Probably, because CLIENT_ASSETS_MANIFEST isn't ready while it's required
// So, we read file (only on first request) instead of importing it
async function getFile (path) {
// Cache file forever
// Cache file
if (cache[path]) {
return Promise.resolve(cache[path])
return cache[path]
}

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -36,14 +40,23 @@ async function getFile (path) {
}

export default async function () {
const basePath = process.env.CLIENT_DIST_PATH
// flow-disable-next-line: This type cannot be coerced to string
const assets = await getFile(`${basePath}/webpack-assets.json`)
// flow-disable-next-line: This type cannot be coerced to string
const faviconsAssets = await getFile(`${basePath}/favicons-stats.json`)
const assets = await getFile(process.env.CLIENT_ASSETS_MANIFEST)
// AutoDLL assets aren't included in CLIENT_ASSET_MANIFEST (webpack stats)
// So they are hardcoded here
const AutoDLLDevOnly = process.env.NODE_ENV === 'development'
? {
vendor: {
js: 'http://localhost:3000/vendor.js'
},
polyfills: {
js: 'http://localhost:3000/polyfills.js'
}
}
: {}

return {
assets,
faviconsAssets
...assets,
...AutoDLLDevOnly
}
}

0 comments on commit c358e0f

Please sign in to comment.