webpack-lazyload

Utility function that allows to attach webpack bundle to your application on demand.

Usage no npm install needed!

<script type="module">
  import webpackLazyload from 'https://cdn.skypack.dev/webpack-lazyload';
</script>

README

webpack-lazyload

Utility function that allows to attach webpack bundle to your application on demand.

Setup

Your application should use webpack and have entry point exported as webpack library:

webpack.config.js:

module.exports = {
    ...
    entry: './entry.js',
    output: {
        ...,
        library: ['lazyload', 'bundleID'], // bundleID - some identificator of your bundled application
        libraryTarget: 'assign',
        ...
    },
    ...

entry.js:

...
import root from './root.js'; // your bundle's entrypoint

const node = document.getElementById('someuniqid'); // someuniqid should be different from bundleID
if (node) {
    ...
    ReactDOM.render(root, node);
    ...
}

export default root; // let the webpack to export a pointer to bundle's entrypoint

Examples