# require.js

> Small AMD loader for bundled AMD modules. No dynamic loading or loader plugin support.

Latest version **1.0.0** (published 2016-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install require.js
pnpm add require.js
yarn add require.js
bun add require.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-01-07 |
| First published | 2016-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ravindra Marella |
| Maintainers | marella |
| Keywords | amd, require.js |

## Links

- npm: https://www.npmjs.com/package/require.js
- Repository: https://github.com/marella/require.js
- Homepage: https://github.com/marella/require.js#readme
- Issues: https://github.com/marella/require.js/issues
- npm.io page: https://npm.io/package/require.js

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-01-07

## README

Small AMD loader for bundled AMD modules. No dynamic loading or loader plugin support.

### define(id, deps, factory)

argument|type
--:|--
id|string
deps|array
factory|function

All modules must have IDs and dependency arrays in their define() calls. [See AMD define()](https://github.com/amdjs/amdjs-api/blob/master/AMD.md#define-function-).

```js
define('dep1', [], function() {
});

define('dep2', [], function() {
});

define('module1', ['dep1', 'dep2'], function(dep1, dep2) {
	// initial setup
	return {
		// exports
	};
});
```

### require(id)

argument|type
--:|--
id|string

Synchronously returns the module export for the module ID represented by the `id` argument. Modules and all dependencies must be defined before calling this function as it does not do dynamic loading. [See AMD require()](https://github.com/amdjs/amdjs-api/blob/master/require.md#requirestring-).

```js
var $ = require('jquery');
```

```js
define('module1', ['dep1'], function(dep1) {
	var dep2 = require('dep2');
	// initial setup
	return {
		// exports
	};
});
```

### Usage
```bash
npm install require.js
```
Bundle *require.js* with other scripts. It should be added before named or bundled AMD modules.
```js
concat([
	'node_modules/require.js/require.min.js', // require.js - define() and require() functions are available from this point
	'node_modules/jquery/dist/jquery.min.js', // jquery is registered as a named amd module 'jquery'
	'src/js/**/*.js' // named amd modules
]);
```

```js
concat([
	'node_modules/jquery/dist/jquery.min.js', // jquery is registered as a global variable '$'
	'node_modules/bootstrap-sass/assets/javascripts/bootstrap.min.js', // bootstrap does not support amd
	'node_modules/require.js/require.min.js', // require.js - define() and require() functions are available from this point
	'src/js/**/*.js' // named amd modules
]);
```

It can also be included before bundled amd modules.
```js
concat([
	'node_modules/require.js/require.min.js', // require.js - define() and require() functions are available from this point
	'build/js/app.build.js' // bundled amd modules - build tool should assign ids and deps array for each module
]);
```

---
_Source: https://npm.io/package/require.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
