Skip to content

Automatically require all packages from your package.json

Notifications You must be signed in to change notification settings

slavaGanzin/fast-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fast-require

Build Status NPM version

Lazy require all packages from your package.json

Inspired by: https://github.com/viktor-ku/auto-require/

Options

Require only needed packages

const $ = require('fast-require')({
  only: ['gulp', 'gulp-stylus', 'gulp-plumber']
})

// $.gulp, $.stylus, $.plumber

Filter packages by name

const $ = require('fast-require')({
  without: ['gulp']
})

// $.stylus, $.plumber, but $.gulp is undefined

Search for package.json in specific folders

const $ = require('fast-require')({
  search: ['src/my-folder/'],
})

// packages from src/my-folder/package.json available as $.[moduleName]

Import into global namespace

require('fast-require')({
  only: ['gulp', 'gulp-notify'],
  global: true
})

// gulp, gulpNotify or global.gulp, global.gulpNotify

Rename

 const $ = require('fast-require')({
  only: ['gulp', 'gulp-notify'],
  as: {gulp: 'g', 'gulp-notify': gn}
})

// $.g $.gn

Import all package functions into root object

const $ = require('fast-require')({
  only: ['request'],
  toRoot: ['request']
})

// $.get, $.post, $.head (all function from request).
//$.request is undefined

Disable auto installation of missing packages

const $ = require('fast-require')({install: false})

Require additional packages: globally installed or core modules

const $ = require('fast-require')({require: ['fs']})

//$.fs

Disable lazy loading

const $ = require('fast-require')({lazy: false})
// All modules loaded at once

const $ = require('fast-require')()

$.gulp //gulp required
$.gulpNotify //gulp-notify required

Patch module

const $ = fastRequire({patch: {
  chai: x => {
    x.patchedMethod = () => 'patched return'
    return x
  },

  fs: require('thenifyAll')
}})

About

Automatically require all packages from your package.json

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published