Skip to content

Repository files navigation

require-overrides

A hacky CommonJS way to alias modules with SSR counterparts.

Example

constoverrides=require('require-overrides');// use 'uhtml-ssr' instead of 'uhtml' when components// are loaded through the server, not the clientoverrides.set('uhtml','uhtml-ssr');// now everyconst{render, html, svg}=require('uhtml');// will point instead at require('uhtml-ssr')

The default export is a callback with attached all Map methods and properties, and it is possible to bootstrap multiple overrides at once.

constoverrides=require('require-overrides');overrides({uhtml: 'uhtml-ssr',// overrides, as callback, will receive all the module detailsuland: (name, ...rest)=>'uland-ssr',});

How to do this via ESM

Until import-maps is officially supported, it is possible to use @node-loader/import-maps, example:

IMPORT_MAP_PATH=test-esm/node.importmap node --experimental-loader @node-loader/import-maps test-esm/index.js

About

A hacky way to alias modules with SSR counterparts

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages