npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bikky/libraryloader

v0.0.120

Published

Bikky's LibraryLoader utililty for exposing node_modules to the client and allowing easy node_module development.

Downloads

2,101

Readme

LibraryLoader

Libraryloader is a utilities library designed to allow for easy loading and rerouting of modules. There are three main functions to the library loader.

  1. Aliased Source Loading: Foremostly the libraryloader allows for loading source files via an alias (e.g. "@Common" for loading files from a common project).
  2. Client Module Loading: The libraryloader allows for the client to load it's installed node_modules in the browser.
  3. Dev node_module Loading: Finally, the libraryloader also allows for the server and the client to load node_modules files from a registered local directory instead of node_modules.

WARNINGS:

LibraryLoader is designed to work with ESM modules. It will not work with bundled files or other loading strategies.

LibraryLoader for the client requires Express.js on the server.

LibraryLoader must be the first import in your file, and subsequent imports in that file must be made with the import() function instead of the keyword, to force them to load afterwards (or they will execute out of order).

Installation:

npm install @bikky/libraryloader

Usage:

A complete example of how to use the libraryloader is shown below:

//This must be the first import in the file:
import { InitialiseServer, InitialiseClient } from "@bikky/libraryloader";

InitialiseServer({
	serverPaths: {
		"@Alias": "../Alias",
	},
	node_modules: {
		server: ["./", "../Main"],
		localMode: false
	},
	logging: "silent"
});

//Other includes and code.

InitialiseClient({
    clientPaths: {
        "@Alias": "../Alias",
    },
    node_modules: {
        client: "./",
        localMode: false
    },
    logging: "silent"
}, expressApp);

LibraryLoader expects for the ExpressApp to be provided for the client's aliases, node_module access or node_module overrides to work.

Aliased Source Loading

The following code will enable the @Alias alias to be used to load files from the ../Alias directory on both the server and the client (path is relative to the server's current working directory).

You only need to supply expressApp and clientPaths if you want the aliases to be usable on the client.

InitialiseServer({
    serverPaths: {
        "@Alias": "../Alias",
    },
    logging: "silent"
});

InitialiseClient({
    clientPaths: {
        "@Alias": "../Alias",
    },
    logging: "silent"
}, expressApp);

Remember to import the /@bikky/libraryloader.js script on the client (instructions below).

Client Module Loading

This code allows the client to load installed node_modules. It need the path from the server's current working directory to the directory containing the client's package.json. This is because all loaded node_modules are compared against the client's package.json to ensure that users aren't getting access to arbitrary scripts.

InitialiseClient({
    node_modules: {
        client: "./"
    },
    logging: "silent"
}, expressApp);

Remember to import the /@bikky/libraryloader.js script on the client (instructions below).

Dev node_module Loading

This next code allows the server and the client to load node_modules from a registered local directory instead of the node_modules folder. This is useful for developing node_modules as it allows for easy switching between source files and the published library.

InitialiseServer({
    node_modules: {
        client: "./",
        localMode: true
    },
    logging: "silent"
});

InitialiseClient({
    node_modules: {
        client: "./",
        localMode: true
    },
    logging: "silent"
}, expressApp);

You can use the binary code to register your source directories:

npx @bikky/libraryloader --registerSource

And if you want to unregister them later:

npx @bikky/libraryloader --unregisterSource

Client Setup:

The LibraryLoader must also be included on the client for it to function. If the LibraryLoader is correctly configured with the express app on the server, then you can include the following script tag in the head of your html file:

On the client import the libraryloader in the <head> like so:

<!-- the following script tag should be the first script tag in any .html file. -->
<script type="text/javascript" src="/@bikky/libraryloader.js"></script>