Creating a plugin for Cogear.JS
Tags: node, cogearjs, javascript, hacktoberfest
Published: 2018-10-09 19:31:23

---
title: Creating a plugin for Cogear.JS
published: true
description: How to craft Cogear.JS plugin.
tags: Node, Cogear.JS, javascript, hacktoberfest
cover_image: https://thepracticaldev.s3.amazonaws.com/i/2q7190qdk8yp86vbccwv.jpg
---

[Cogear.JS](https://cogearjs.org) is a modern static websites generator built with [Node.JS](https://nodejs.org) and based on [Webpack](https://webpack.js.org).

If you have missed introduction to **Cogear.JS** article series, you're welcome:
{% link https://dev.to/codemotion/cogearjs--modern-static-websites-generator-450a %}
{% link https://dev.to/cogear/creating-a-blog-with-cogearjs-21af %}
{% link https://dev.to/cogear/deploying-cogearjs-generated-site-to-the-nowsh-367m %}

It's time to talk about crafting plugins.

Let’s start from giving a definition to a plugin.

> Plugin is a module which can hook into the system core to change its behavior.

**Node.JS** has first-party [EventEmitter](https://nodejs.org/api/events.html) – a huge API surface with synchronous event emitting, magic error event and flawed memory leak detected. **Cogear.JS** uses the small library called [Emittery](https://github.com/sindresorhus/emittery), which has none of that.

**Cogear.JS** core is built from modules. Take a look at [the main script file](https://github.com/codemotion/cogear.js/blob/master/lib/cogear.js) in the repository and all modules it has plugged in.

### Source of `./lib/cogear.js`
![Source of ./lib/cogear.js](https://thepracticaldev.s3.amazonaws.com/i/3az9aq4mxh88vwmrzrmv.png)

Moreover **Cogear.JS** main object class is globally available and extends Emittery, so events can be called throughout the entire code.

**Cogear.JS** as an inheritor of **Emittery** has two methods – `on` and `emit`. With `on` method you can add callback function for named event. And with `emit` method you call this event with or without arguments. 

Read more at the [Emittery docs](https://github.com/sindresorhus/emittery).

Arguments can be easily fetched from the context of globally available `cogear` instance. Or you can pass them manually.

![Cogear on ane emit methods](https://thepracticaldev.s3.amazonaws.com/i/yvvbjdysc24wlfz03i3g.png)

To look through all the events use [search](https://github.com/codemotion/cogear.js/search?utf8=✓&q=cogear.emit&type=) on GitHub repository. It will show all the event which you can hook into.

So what is a plugin in **Cogear.JS** environment? It’s a simple object with only one method required – which is called `apply`.

To engage you in further learning I encourage you to see a new video from our YouTube-channel:
{% youtube V427GA4BZHk %}

It will reveal the topic of plugin crafting.

You can also dive into proper docs section:
https://cogearjs.org/docs/plugins

And discover plugins in awesome-cogear repository:
{% github codemotion/awesome-cogear %}

If you like this video, please, subscribe [Cogear.JS YouTube-channel](https://www.youtube.com/channel/UCYVvgPLMfRwA2K_ledHCZcw) and giva a star to the projects repository:

{% github codemotion/cogear.js %}

# Join the Social Impact Hacktoberfest Challenge
![Join the Social Impact Hacktoberfest Challenge](https://user-images.githubusercontent.com/121322/46319645-ab50e200-c58f-11e8-8dd0-cf7a4b1a610e.png)

Learn how to win a cool t-shirt taking part in [Hacktoberfest](https://hacktoberfest.digitalocean.com) via contributing to [Cogear.JS](https://cogearjs.org).

Right now we encourage developers to:
1. [Create a plugin for React](https://github.com/codemotion/cogear.js/issues/6) (just add a loader to Webpack).
2. [Create a Bootstrap 4 theme](https://github.com/codemotion/cogear.js/issues/7).