# an

> Angular + NPM: Publish your AngularJS modules to npm

Latest version **0.0.8** (published 2016-02-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install an
pnpm add an
yarn add an
bun add an
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2016-02-06 |
| First published | 2014-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Andrei Kashcha |
| Maintainers | anvaka |

## Links

- npm: https://www.npmjs.com/package/an
- Repository: https://github.com/anvaka/an
- Homepage: https://github.com/anvaka/an#readme
- Issues: https://github.com/anvaka/an/issues
- npm.io page: https://npm.io/package/an

## Recent versions

- 0.0.8 (latest) — 2016-02-06
- 0.0.7 — 2014-09-09
- 0.0.6 — 2014-07-10
- 0.0.5 — 2014-06-10
- 0.0.4 — 2014-05-10
- 0.0.3 — 2014-03-30
- 0.0.2 — 2014-02-21
- 0.0.1 — 2014-02-19

## README

# Angular + npm

Build angular 1.x apps with power of npm modules.

# usage

To start using `an` just replace `angular.{controller|directive|...}('name', fn)`
with: `module.exports = require('an').{controller|...}('name', fn)`

Then in your main file where you bootstrap angular application:

``` js
var app = angular.module('yourModule', [/* your regular deps */]);
// flush all registered modules:
require('an').flush(app);
```

## Demo

``` js
// controller.js
module.exports = require('an').controller('AppCtrl', function($scope) {
  $scope.message = 'Hello World';
});

// app.js
require('./controller.js'); // just make sure the controller is registered

var app = angular.module('myApp', []);
// flush controller into app:
require('an').flush(app);

// this is equivalent to:
// app.controller('AppCtrl', function() {...});
```

``` html
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
</head>
<body ng-controller='AppCtrl'>
    <h1>{{message}}</h1>
    <script src='bundle.js'></script>
</body>
</html>
```

See [demo folder](https://github.com/anvaka/an/tree/master/demo) for the same code.
Browserified output of the demo folder (`browserify ./demo/app.js > ./demo/bundle.js`)
can be found here: https://anvaka.github.io/an/demo

# How?

The idea is simple: avoid using `angular.module` in npm package, and delay
directives registration up to the point when application is bootstrapped.

E.g. instead of doing:

``` js
  var myModule = angular.module(???, []);
  myModule.directive(???, function myDirective() {/* */});
```

Do:

``` js
  require('an').directive(function myDirective() {});
```

When you ready to bootstrap application, collect all directives and register them in your main application module:

``` js
  require('an').flush();
```


# Drawbacks

This approach is still not perfect and requires certain discipline to not forget
register your directives via `an`. I can also see potential problems with names
collision, versioning (especially when `an` itself is updated).
This module is [really simple](https://github.com/anvaka/an/blob/master/index.js)
at the moment, and maybe there is a better way of sharing angular directives on
npm.

Please let me know.

# install

With [npm](https://npmjs.org) do:

```
npm install an
```

# license

MIT

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