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

flexi-require

v1.2.5

Published

a browserify plugin, to enable you require bower components and non package components just like node modules

Downloads

9

Readme

flexi-require

NPM

Let flexi-require plugin require bower and non package components for you when building bundles, then you can require them as normal node modules in application codes.
You can also provide external config, to guide flexi-require to external some bower and non package components, which is useful when when building multiple bundles.

p.s. bower and non package components is optional, if want to use bower, install it.

install

npm install flexi-require

usage

Programmatic API

In your task runner like gulp, add this plugin to browserify:

b.plugin('flexi-require', {
	// files:  [], // not set is default. (equal files: browserify entries)
	// or
	files:  ['xxx.js'],

	require: ['*', './my_modules/mycomp1.js:mycomp1', 'comp2', 'base62/lib/base62'],
	external: ['comp3', 'comp4'],
	ignore: ['comp5'],
	// noreset: true, // disable run again when browserify 'reset' event
});

Then, in js codes, you can require it like normal node module:

// in xxx.js
var mycomp1 = require('mycomp1');
var comp2 = require('comp2');
...

Command Line

Use conf file,

$ browserify entry.js -d -p [flexi-require --conf conf.json] > bundle.js

Use a node of the conf json,

$ browserify entry.js -d -p [flexi-require --conf conf.json --confnode aa.bbb] > bundle.js

workdir

By default, flexi-require will try to find the working bower components dir when using it, from the dir of process.cwd(). But you can specify another one.

In programmatic API, pls use like b.plugin(flexiRequire.workdir(thedir), {..}). In command line, pls use parameter --workdir thedir.

p.s. feel free to use it side by other plugins/transforms, since it's a standard browserify plugin, no hack, no change to your codes.

options

b.plugin('flexi-require', {
	// files:  [], // not set is default. (equal files: browserify entries)
	// or
	files:  ['xxx.js'],
	//       ['name', 'path:alias', 'submodule:alias'],

	require: ['*', './my_modules/mycomp1.js:mycomp1', 'base62/lib/base62:libbase62'],
	external: ['comp3', 'comp4'],
	ignore: ['comp5'],
	// noreset: true, // disable run again when browserify 'reset' event
});

action: string, guide flexi-require to require/external specified bower and non package components in files(ignore used to ignore in already configured component) ; available values: files | require | external | ignore.

Notes: name_or_path format: name_or_path[:alias], and name_or_path can be component name, submodule like 'base62/lib/base62' or file path.

Additional Rules:

  • if both require/external and alias declared an alias for a component, using alias in the order priority, weak < require * < external * < require comp1 < external comp1 < strong

    for example

options = {
	require: ['comp1'],
	external: ['*']
};
...
require component is `comp1` and external components is other all, in this case.

run test

You optional ensure related node modules (for bower) components (for test codes) installed, then run npm test.

For first time, you can do it like this:

flexi-require $ npm install
flexi-require $ npm test

	> [email protected] test ~/repos/flexi-require
	> mocha --reporter nyan

	 1   -__,------,
	 0   -__|  /\_/\
	 0   -_~|_( ^ .^)
		 -_ ""  ""

	  1 passing (139ms)

flexi-require $

license

MIT