npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auto-require

v3.1.0

Published

No need to require any packages now

Downloads

29

Readme

auto-require

Standard - JavaScript Style Guide

It's the best way to automatically require your packages

Checkout changelog also

Motivation

I was so tired to write a lot constiable definitions in my build scripts, so I have decided to write a tiny library for including them automatically. So it's basically the library for those purposes, but you can use it everywhere.

Features

  • Requires and caches modules
  • Avoid including all packages from node_modules instead include packages specified in packages.json only
  • globaly option, so you can avoid using any var (like $ in examples)

install

npm install auto-require

Get started

There are examples using gulp, but you can use this package with anything else.

// get all modules from 'node_modules/' only
const $ = require('auto-require')()

// Do you see any gulp, plumber, pug const definitions here?
$.gulp.task('default', () => {
	$.gulp.src('src/*.plumber')
		.pipe($.plumber())
		.pipe($.pug())
		.pipe($.gulp.dest('dest/'))
})

Options

1. Get modules you only need

const options = {
	only: ['gulp', 'gulp-stylus', 'gulp-plumber']
}

const $ = require('auto-require')(options)

// $.gulp, $.stylus, $.plumber only avaliable

2. Get modules you only need from different places

Note that paths are absolute and begins from the root of your project (it's where the package.json is)

const options = {
	search: ['src/my-folder/'],
	only: ['customize']
}

const $ = require('auto-require')(options)

// $.customize only avaliable

3. Get all modules without any

const options = {
	without: ['kaktuz', 'zepto']
}

const $ = require('auto-require')(options)

// $.kaktuz and $.zepto are not avaiable at all

4. If only and without, then without will be ignored

const options = {
	without: ['gulp', 'zepto']
	only: ['gulp', 'zepto']
}

const $ = require('auto-require')(options)

// $.zepto and $.gulp avaliable only

5. Globaly

By using it that way you can get all vars as you specified them, but be careful as it's global namespace.

const options = {
	only: ['gulp', 'gulp-notify'],
	globaly: true
}

require('auto-require')(options)

// gulp and notify avaliable globaly (only)

//All global imports are guarded and can't be overriden:
gulp = {}
// Error: gulp is already defined
}

6. As

You can rename module before import.

const options = {
	only: ['gulp', 'gulp-notify'],
  as: {gulp: 'g', 'gulp-notify': 'gn'}
  
// You can access gulp and gulp-notify as $.g and $.gn
const $ = require('auto-require')(options)

7. toRoot

You can import all functions of module into root object.

const options = {
	only: ['request'],
	toRoot: ['request']
}

// $.get, $.post, $.head (all function from request). But not $.request
const $ = require('auto-require')(options)

What it does?

It takes all modules in your node_modules folder by default using data from package.json and exports it as one module.

Quick example

  • express via $.express or express if globaly set to true (and in next examples as well)
  • browser-sync via $.browserSync
  • gulp via $.gulp
  • gulp-inline-css via $.inlineCss

What about jQuery or build tools?

No, you'll not need to write full module name. The first part of the module name will be cut in this case. For example we have gulp-pug module. How we can access it? Actually it's pretty straightforward - via $.pug. As you can see the first part of the gulp-pug has been cut.

This tool works fine with gulp, grunt, broccoli.

Other access examples

  • gulp via $.gulp
  • gulp-plumber via $.plumber
  • gulp-inline-css via $.inlineCss
  • grunt via $.grunt
  • grunt-shell via $.shell
  • grunt-conventional-changelog via $.conventionalChangelog
  • broccoli-file-contents-to-json via $.fileContentsToJson
  • express via $.express
  • browser-sync via $.browserSync
  • andyet-express-auth via $.andyetExpressAuth

Test

npm install
npm test

License

Licensed under MIT.