包详细信息

@artdeco/pirates

artdecocode5MIT1.0.0

[fork] Properly Hijack Require In ES6 For Google Closure Compiler.

pirates, artdeco

自述文件

@artdeco/pirates

npm version

@artdeco/pirates is a fork of Properly Hijack Require In ES6 For Google Closure Compiler.

yarn add @artdeco/pirates

Table 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 © Art Deco 2019 Tech Nation Visa Tech Nation Visa Sucks

更新日志

24 April 2019

1.0.0

  • [package] Publish version v1.0.0.

0.0.0