Server-side utility to flush Webpack chunks for SSR with React Loadable or similar packages (e.g., react-universal-component). Current version is 2.0.3 (last released Oct 2018, appears to be in maintenance mode with no recent updates). It extracts CSS and JS chunks rendered on the server and returns them as string tags for injection in the HTML response. Key differentiators: supports Webpack 4 aggressive code splitting, works with chunkNames or moduleIds, and integrates seamlessly with babel-plugin-universal-import. Compared to alternatives like react-loadable's own server-side logic, this library provides more flexibility for complex chunking strategies.
npm install webpack-flush-chunksVerified import paths — ran on the pinned version, not inferred.
Shows server-side rendering with flushChunks to inject JS and CSS tags for rendered chunks.
Ensure your webpackStats include chunk IDs. Use chunkNames option instead of moduleIds if migrating from v1.
Switch to using chunkNames from react-universal-component's flushChunkNames or equivalent.
Use webpack's --json flag or compiler.getStats() in Node to generate stats with chunks info.
Pass chunkIds in the options object: flushChunks(webpackStats, { chunkIds: [...] })Upgrade to v2.0.2+ which includes unique filter for CSS and JS.
Use: import flushChunks from 'webpack-flush-chunks' (ESM) or const flushChunks = require('webpack-flush-chunks') (CJS).Ensure you pass the proper webpack stats object (e.g., from stats.json). Verify it contains assetsByChunkName and chunks.
Check the chunk names from your code splitting library (e.g., react-universal-component). Ensure they match the actual output chunk names.
Upgrade to v2.0.2 or later.