@artdeco/pirates
@artdeco/pirates is a fork of Properly Hijack Require In ES6 For Google Closure Compiler.
yarn add @artdeco/piratesTable Of Contents
API
The package is available by importing its default function:
import addHook from '@artdeco/pirates'
addHook(
hook: function,
conf?: Config,
): function
Add a require hook. Returns a function that allows to revert the hook.
_pirates.Config: Options for the program.
| Name | Type | Description | Default | |
|---|---|---|---|---|
| exts | (string \ | !Array<string>) | The extension or extensions to hook. Should start with .. |
.js |
| matcher | (path: string) => boolean | A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise. | - | |
| ignoreNodeModules | boolean | Auto-ignore node_modules. Independent of any matcher. |
false |
import addHook from '@artdeco/pirates'
import { relative } from 'path'
addHook((code, filename) => {
const rel = relative('', filename)
return `console.log('hooked source code from %s:', '${rel}')
${code}`
})
require('./source')hooked source code from example/source.js:
hello world
Copyright
Original Author: Ari Porad
|
© Art Deco 2019 |
|
Tech Nation Visa Sucks |
|---|