0.0.120 • Published 9 hours ago

@bikky/libraryloader v0.0.120

Weekly downloads
-
License
-
Repository
-
Last release
9 hours ago

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>
0.0.120

9 hours ago

0.0.106

5 days ago

0.0.105

5 days ago

0.0.104

5 days ago

0.0.103

5 days ago

0.0.109

5 days ago

0.0.108

5 days ago

0.0.107

5 days ago

0.0.102

5 days ago

0.0.101

5 days ago

0.0.100

5 days ago

0.0.117

5 days ago

0.0.115

5 days ago

0.0.114

5 days ago

0.0.119

5 days ago

0.0.118

5 days ago

0.0.113

5 days ago

0.0.112

5 days ago

0.0.111

5 days ago

0.0.110

5 days ago

0.0.95

5 days ago

0.0.96

5 days ago

0.0.97

5 days ago

0.0.98

5 days ago

0.0.99

5 days ago

0.0.94

9 days ago

0.0.86

9 days ago

0.0.87

9 days ago

0.0.88

9 days ago

0.0.89

9 days ago

0.0.90

9 days ago

0.0.91

9 days ago

0.0.92

9 days ago

0.0.93

9 days ago

0.0.84

10 months ago

0.0.85

10 months ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.80

2 years ago

0.0.81

2 years ago

0.0.82

2 years ago

0.0.83

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.73

2 years ago

0.0.74

2 years ago

0.0.75

2 years ago

0.0.76

2 years ago

0.0.32

2 years ago

0.0.77

2 years ago

0.0.33

2 years ago

0.0.78

2 years ago

0.0.34

2 years ago

0.0.79

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.70

2 years ago

0.0.71

2 years ago

0.0.72

2 years ago

0.0.62

2 years ago

0.0.63

2 years ago

0.0.64

2 years ago

0.0.65

2 years ago

0.0.66

2 years ago

0.0.67

2 years ago

0.0.68

2 years ago

0.0.69

2 years ago

0.0.60

2 years ago

0.0.61

2 years ago

0.0.59

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.56

2 years ago

0.0.57

2 years ago

0.0.58

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.15

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.18

2 years ago

0.0.19

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.0

2 years ago