Socket
Socket
Sign inDemoInstall

enhanced-require

Package Overview
Dependencies
3
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

enhanced-require


Version published
Weekly downloads
105
decreased by-13.22%
Maintainers
1
Install size
88.3 kB
Created
Weekly downloads
 

Readme

Source

enhanced-require

More features for node.js require.

  • loader support
  • require.ensure
  • AMD require, define (from require.js)
  • require.context
  • Hot Code Replacement

Asynchron require functions are really async. They do not use the sync node.js require, but use a async resolving and async readFile.

Single module

Add this line to a node.js module to activate the enhanced features in that module:

require = require("enhanced-require")(module);

// and optionally if your want require.js style defines:
if(typeof define != "function") var define = require.define;

Than you can use them:

// use loaders
var fileContent = require("raw!"+__filename);

// use loaders automatically
var template = require("./my-template.jade");

var html = template({content: fileContent});

// use require.context
var directoryRequire = require.context("raw!./subdir");
var txtFile = directoryRequire("./aFile.txt");

// use require.ensure
require.ensure(["./someFile.js"], function(require) {
	var someFile = require("./someFile.js");
});

// use AMD define
require.define(["./aDep"], function(aDep) {
	aDep.run();
});

// use AMD require
require(["./bDep"], function(bDep) {
	bDep.doSomething();
});

Complete application

Create a seperate entry module and require your original entry module:

require = require("enhanced-require")(module, {
	recursive: true, // enable for all modules
	hot: true, // enable hot code replacement
	watch: true // watch for changes
});

require("./startup");

You can use all features in startup.js and all required modules.

For hot code reloading you need to follow the hot code reloading spec.

Future Plans

  • cli tool

License

Copyright (c) 2012 Tobias Koppers

MIT (http://www.opensource.org/licenses/mit-license.php)

FAQs

Last updated on 26 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc