import express from 'express'; import path from 'path'; import React from 'react'; import { renderToString } from 'react-dom/server'; import Loadable from 'react-loadable'; import { getBundles } from 'react-loadable-ssr-addon'; import App from './components/App'; const manifest = require('./dist/react-loadable-ssr-addon.json'); const server = express(); server.use('/dist', express.static(path.join(__dirname, 'dist'))); server.get('*', (req, res) => { const modules = new Set(); const html = renderToString( modules.add(moduleName)}> ); const bundles = getBundles(manifest, [...manifest.entrypoints, ...Array.from(modules)]); const styles = bundles.css || []; const scripts = bundles.js || []; res.send(` React Loadable SSR Add-on Example ${styles.map(style => { return ``; }).join('\n')}
${html}
${scripts.map(script => { return `` }).join('\n')} `); }); Loadable.preloadAll().then(() => { server.listen(3003, () => { console.log('Running on http://localhost:3003/'); }); }).catch(err => { console.log(err); });