Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-require-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-require-webpack-plugin

Webpack plugin to automatically require the module itself

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

auto-require-webpack-plugin

Webpack plugin to automatically require the module itself, if module name defined. For Example:

(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory();
	else if(typeof define === 'function' && define.amd)
		define("common/view", [], factory);
	else if(typeof exports === 'object')
		exports["common/view"] = factory();
	else
		root["common/view"] = factory();
})(this, function() {
  /* Module code here */
});

// When using require, call the module automatically
typeof define === 'function' && define.amd && require(['common/view']);

Usage

new AutoRequirePlugin(options)

/* Use constructor options directly */
var options = true;

module.exports = {
  plugins: [
    new AutoRequirePlugin(options)
  ]
};

Or

/* Use `output.autoRequire` to set options */
var options = true;

module.exports = {
  output: {
    autoRequire: options
  },
  plugins: [
    new AutoRequirePlugin()
  ]
};

There are two ways to configure AutoRequirePlugin: constructor's parameter or output.autoRequire. The latter will override constructor's parameter.

Examples

Type of options can be boolean, string, RegExp, function and Array.

Require all modules

module.exports = {
  plugins: [
    new AutoRequirePlugin(true)
  ]
};

Require module with specific name

module.exports = {
  plugins: [
    new AutoRequirePlugin('common/view')
  ]
};

Require module(s) matching regular expression

module.exports = {
  plugins: [
    new AutoRequirePlugin(/^common/)
  ]
};

Require module(s) testing by function

module.exports = {
  plugins: [
    new AutoRequirePlugin(function (moduleName) {
      return moduleName.split('/').length > 2;
    })
  ]
};

More complex case

module.exports = {
  plugins: [
    new AutoRequirePlugin([
      /^pages\/.+/,
      function (moduleName) {
        return moduleName.indexOf('common') >= 0 && moduleName.indexOf('widgets') < 0;
      }
    ])
  ]
};

Keywords

FAQs

Package last updated on 16 Nov 2016

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc