# init-file-loader

> Loader for Template, for loading files onto a custom view collection inside a vinyl plugin.

Latest version **0.1.1** (published 2015-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install init-file-loader
pnpm add init-file-loader
yarn add init-file-loader
bun add init-file-loader
```

## 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.1.1 |
| Published | 2015-04-29 |
| First published | 2015-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |

## Links

- npm: https://www.npmjs.com/package/init-file-loader
- Repository: https://github.com/jonschlinkert/init-file-loader
- Issues: https://github.com/jonschlinkert/init-file-loader/issues
- npm.io page: https://npm.io/package/init-file-loader

## Recent versions

- 0.1.1 (latest) — 2015-04-29
- 0.1.0 — 2015-04-29

## README

# init-file-loader [![NPM version](https://badge.fury.io/js/init-file-loader.svg)](http://badge.fury.io/js/init-file-loader)

> Loader for Template, for loading files onto a custom view collection inside a vinyl plugin.

## Install with [npm](npmjs.org)

```bash
npm i init-file-loader --save
```

## Usage

**Register the loader**

Register `init-file-loader` as a custom loader:

```js
app.loader('file', [require('init-file-loader')]);
```

`app` is used as a placeholder for [Verb], [Assemble], [Generate](https://github.com/generate/generate), or any application based on [Template].

**Use the loader**

This is used in the built-in `init` plugin in Assemble and Verb.

* The `.getTask()` method is used to get the name (`id`) of the currently running task.
* The `.create()` method uses the `id` to create a custom template type for that task
* The `file` loader is assigned to the template type. This basically means that the `file` loader will be called on every file that is loaded.

**Example usage in a plugin**

```js
var through = require('through2');

module.exports = function myPlugin() {
  var app = this;
  var id = this.getTask();

  // create a template type for vinyl files and assign the loader
  if (!app.hasOwnProperty(id)) {
    // `id` is something like `task_foo`
    app.create(id, ['file']);
  }

  return through.obj(function (file, enc, cb) {

    // Here, we call the method we created above, which would 
    // be something like `app.task_foo()`. This is the same exact 
    // thing that `assemble.page()` does, or `verb.docs()`.
    // 
    // Instead of `pages` or `docs`, the loader we're using will 
    // convert the vinyl file to a template and add it to the 
    // `task_foo` collection.
    app[id](file);
    cb();
  }, function (cb) {
    app.pushToStream(id, this);
    cb();
  });
};
```

## Related projects

* [assemble](http://assemble.io): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](http://assemble.io)
* [middleware-utils](https://github.com/jonschlinkert/middleware-utils): Utils for Template middleware.
* [template](https://github.com/jonschlinkert/template): Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… [more](https://github.com/jonschlinkert/template)
* [template-utils](https://github.com/jonschlinkert/template-utils): Utils for [Template](https://github.com/jonschlinkert/template).
* [verb](https://github.com/assemble/verb): Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… [more](https://github.com/assemble/verb)

## Running tests

Install dev dependencies:

```bash
npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/init-file-loader/issues)

## Author

**Jon Schlinkert**

[github/jonschlinkert](https://github.com/jonschlinkert)
[twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 29, 2015._

<!-- reflinks generated by verb-reflinks plugin -->

[assemble]: http://assemble.io
[template]: https://github.com/jonschlinkert/template
[verb]: https://github.com/assemble/verb

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