diff --git a/src/server/ssr/stats.js b/src/server/ssr/stats.js index 5e569b33..5915c6fe 100644 --- a/src/server/ssr/stats.js +++ b/src/server/ssr/stats.js @@ -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) => { @@ -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 } }