slash-node-modules-loader
v1.0.3
Published
Use with -r slash-node-modules-loader to be able to require from require('/node_modules/:somedir/somefile.js') to have it map to :somedir/somefile.js
Downloads
29
Readme
Slash Node Modules Loader
This module rewrites paths during require() so that if it sees a prefix of '/node_modules/' it is removed.
Example usage:
node -r slash-node-modules-loader ./index.js
// in index.js
const path = require('/node_modules/path');
const express = require('/node_modules/express');
const request = require('express');
It also works with esm for ES Modules.
node -r esm -r slash-node-modules-loader ./index.js
// in index.js
import HTMLElementPlus from '/node_modules/HTMLElementPlus';
The purpose of this is to allow ES Modules to be used isomorphicly by exposing '/node_modules/' as a route on the server. So any packages from npm can be used on the client and server without needing to use proxy modules.