<commit_before># Using wire.js

1. [As a Module](#module)
	1. [AMD](#amd)
	1. [CommonJS](#commonjs)
1. [As an AMD Plugin](#amd-plugin)
1. [As a Factory](#factory)
1. [By Injecting wire](#injecting-wire)

## Module

Wire can be used as a module in AMD or CommonJS environments.  You can [install it using one of the supported methods](get.md).

In either environment, wire is simply a function.

### AMD

Once you've installed wire into your AMD environment and configured your loader, you can load wire as you would any other module:

```js
// Using pure AMD
// List wire as a dependency
define(['wire'], function(wire) {
	// use wire()
});
```

```js
// Using AMD-wrapped CommonJS
define(function(require) {
	// Use the standard AMD local require to load wire
	var wire = require('wire');
});
```

### CommonJS

Similarly, once you've installed wire into your CommonJS environment, simply load it:

```js
var wire = require('wire');
```

## AMD Plugin

Wire can be used as an AMD plugin in any AMD loader that supports the [AMD plugin API](https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins), for example: [curl](https://github.com/cujojs/curl) [RequireJS](http://requirejs.org), and [Dojo](http://dojotoolkit.org).  This can be a very convenient way to bootstrap a front-end application.

Once you've installed wire into your AMD environment and configured your loader:

```js
// Assume app/main is the main wire spec that bootstraps the application
curl(['wire!app/main']);
```

For more examples of using wire as an AMD plugin to bootstrap applications, see the [Example Apps](introduction.md#example-apps)

## Factory

Wire can be used as a [factory](concepts.md#factories) from within a [wire spec](concepts.md#wire-specs) to wire other specs and use them as components.  This makes it easy to modularize applications into higher level units that can be packaged and tested independently.

Here is a simple example excerpt from a wire spec:

```js
// aComplexView is defined by its own wire spec that pulls together
// many components, e.g. html templates, css, internationalization files,
// and Javascript behavior, into a single component.<commit_msg>add information about bundling/concatenating modules<commit_after># Using wire.js

1. [As a Module](#module)
	1. [AMD](#amd)
	1. [CommonJS](#commonjs)
1. [As an AMD Plugin](#amd-plugin)
1. [As a Factory](#factory)
1. [By Injecting wire](#injecting-wire)

## Module

Wire can be used as a module in AMD or CommonJS environments.  You can [install it using one of the supported methods](get.md).

In either environment, wire is simply a function.

### AMD

Once you've installed wire into your AMD environment and configured your loader, you can load wire as you would any other module:

```js
// Using pure AMD
// List wire as a dependency
define(['wire'], function(wire) {
	// use wire()
});
```

```js
// Using AMD-wrapped CommonJS
define(function(require) {
	// Use the standard AMD local require to load wire
	var wire = require('wire');
});
```

### CommonJS

Similarly, once you've installed wire into your CommonJS environment, simply load it:

```js
var wire = require('wire');
```

## AMD Plugin

Wire can be used as an AMD plugin in any AMD loader that supports the [AMD plugin API](https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins), for example: [curl](https://github.com/cujojs/curl), [RequireJS](http://requirejs.org), and [Dojo](http://dojotoolkit.org).  This can be a very convenient way to bootstrap a front-end application.

Once you've installed wire into your AMD environment and configured your loader:

```js
// Assume app/main is the main wire spec that bootstraps the application
curl(['wire!app/main']);
```

You should concatenate all the modules of your app before deploying it to production.  Wire's AMD plugin supports AMD bundling via cujoJS's [cram](http://know.cujojs.com/downloads#alacarte).  Other people have reported success using Pieter Vanderwerff's [wire-rjs plugin](https://github.com/pieter-vanderwerff/wire/blob/rjs-build/builder/rjs.js), which should be placed in the wire/builder folder prior to running rjs.

For more examples of using wire as an AMD plugin to bootstrap applications, see the [Example Apps](introduction.md#example-apps)

## Factory

Wire can be used as a [factory](concepts.md#factories) from within a [wire spec](concepts.md#wire-specs) to wire other specs and use them as components.  This makes it easy to modularize applications into higher level units that can be packaged and tested independently.

Here is a simple example excerpt from a wire spec:

```js
// aComplexView is defined by its own wire spec that pulls together
// many components, e.g. html templates, css, internationalization files,
// and Javascript behavior, into a single component.
{'fraction_non_alphanumeric': 0.10839598997493734, 'fraction_numerical': 0.002506265664160401, 'mean_word_length': 4.46689497716895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1397570', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1327, 'n_words': 612}