New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

amd-inject-loader

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amd-inject-loader

A simple webpack inject loader for AMD-style code

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50
decreased by-1.96%
Maintainers
3
Weekly downloads
 
Created
Source

AMD injection loader for webpack

What Is It

This is a simple webpack loader that allows you to override any dependency requested at the top of your code file in a normal define function block. It is currently very limited in scope. It doesn't handle nested require statements, and it doesn't overwrite or shim the require method itself.

If you are looking for something that works with CommonJS code, try the inject-loader.We tried that loader first, but it didn't work with AMD code and didn't work with our code formatting style, so we whipped this up to meet our immediate testing needs. The API is similar, but you don't need to specify ahead of time which dependencies you want to inject or leave alone. Simply pass in whatever injections you want each time you call the factory method. It can even change between tests in the same file.

Usage

If working with a code file that looks like this:

myfile.js

define( [ "lodash", "customApi" ], function () {
	return {
		init: function () {
			customApi.run()
		}
	}
});

You could inject a different customApi like this:

myfile.spec.js

var myfileInjector = require( "amd-inject!./myfile" );
var myfile = myfileInjector({
	customApi: {
		run: function () {
			console.log( "A new run definition" );
		}
	}
});

myfile.init(); // Outputs A new run definition

Options

To customize options, add a amdInjectLoader key to your webpack config file:

{
	loaders: [ ... ],
	...
	amdInjectLoader: {
		istanbul: true,
		stripComments: true
	}
}
  • istanbul - true or false (Defaults to false) – Include istanbul ignore blocks on the lines that handle the injection
  • stripComments - true or false (Defaults to false) – Strip comments from multiline dependency declarations

Documentation: Using loaders

License

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

Keywords

FAQs

Package last updated on 18 Oct 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