require.dist

require.dist =============

Usage no npm install needed!

<script type="module">
  import requireDist from 'https://cdn.skypack.dev/require.dist';
</script>

README

require.dist

Build Status

require.dist provides a mechanism to inline an asset within a module by embedding the asset itself or a reference to it for on-demand loading at runtime.

Install

npm install require.dist

npm test

Usage

Component.js

exports.name = "Component";

main.js

    var ComponentReference = require.dist("./Component.js");

    ComponentReference().then(function (Component) {

        ASSERT.equal(Component.name, "Component");
    });

ComponentReference will either return the embedded asset or load the asset based on an embedded reference depending on which mode the source code was built in.

For more examples see ./UseCases.

Provenance

Original source logic under Free Public License by Christoph Dorn