Load chunks via XHR + eval, instead of creating <script>
elements.
Replaces webpack's default require.ensure
runtime function so it loads chunks via XMLHttpRequest + eval, instead of adding <script>
elements to the DOM.
Useful if you're rendering your React app on the server, mounting the client app on the root window.document
element, and using code splitting. Without this plugin, the server-rendered markup will differ from the client markup and React will fail to reuse the markup, since webpack will inject additional <script>
elements into the <head>
before React reconciles with the DOM.
npm install xhr-eval-chunk-webpack-plugin
// webpack.config.js
import XhrEvalChunkPlugin from 'xhr-eval-chunk-webpack-plugin';
// or:
// const XhrEvalChunkPlugin = require('xhr-eval-chunk-webpack-plugin').default;
export default {
// ...
plugins: [
// ...
new XhrEvalChunkPlugin(),
],
};