@file-services/commonjs
v9.4.1
Published
Isomorphic, fs-agnostic implementation of the Node commonjs module system.
Downloads
4,322
Readme
@file-services/commonjs
Isomorphic, fs-agnostic implementation of Node's CommonJS module system.
Getting started
Install library in project:
npm i @file-services/commonjs
Then, use the programmatic API:
import { createCjsModuleSystem } from "@file-services/commonjs";
import { createMemoryFs } from "@file-services/memory";
const fs = createMemoryFs({
"some-folder": {
"index.js": `module.exports = 'exported value'`,
},
});
const moduleSystem = createCjsModuleSystem({ fs });
const evaluated = moduleSystem.requireModule("/some-folder/index.js");
// evaluated === 'exported value'
License
MIT