1. @ava/require-precompiled
Require extension that allows for caching/precompiling
@ava/require-precompiled
Package: @ava/require-precompiled
Created by: avajs
Last modified: Mon, 04 Apr 2022 16:41:56 GMT
Version: 1.0.0
License: MIT
Downloads: 22,841
Repository: https://github.com/avajs/require-precompiled

Install

npm install @ava/require-precompiled
yarn add @ava/require-precompiled

require-precompiled

Modifies require() so you can load precompiled module sources.

Install

$ npm install --save require-precompiled

Usage

 const installPrecompiler = require('require-precompiled');
const cache = require('my-cache-implementation');

installPrecompiler(filename => {
	if (cache.hasEntryFor(filename)) {
		return cache.getPrecompiledCode(filename);
	}
	// fall through to underlying extension chain
	return null;
});

// any module required from this point on will be checked against the cache
const foo = require('some-module');

API

 function installPrecompiler(
	loadSource: (filename: string) => string | null,
	ext = '.js',
): void

The loadSource() function should return a source string when a precompiled source is available. Return null to fall back to Node.js' default behavior.

By default the precompiler is installed for .js files. You can specify alternative extensions by providing the second argument:

 installPrecompiler(filename => {
	// ...
}, '.cjs')

License

MIT © James Talmage

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code