Skip to content

Instantly share code, notes, and snippets.

@dstevensio
Last active October 31, 2016 21:17
Show Gist options
  • Save dstevensio/4b12e9ad71599e4090b1 to your computer and use it in GitHub Desktop.
Save dstevensio/4b12e9ad71599e4090b1 to your computer and use it in GitHub Desktop.
rejoice + npm = awesome

Brand new project, create dirs "lib/modules", "lib/templates", "config"

lib/modules/home/index.js :

exports.register = function (server, options, next) {

  server.route({
    path: '/',
    method: 'GET',
    handler: function (request, reply) {

      reply.view('home', {title: 'Home Page'});

    }
  });

  next();

};

exports.register.attributes = {
  pkg: require('./package.json')
};

lib/modules/home/package.json :

{
  "name": "exampleHome",
  "version": "0.0.1"
}

lib/templates/layout.html :

<!DOCTYPE html>
<html>
<head>
  <title>{{title}}</title>
</head>
<body>
  {{{content}}}
</body>
</html>

lib/templates/home.html :

<p>Home Page!</p>

config/manifest.json :

{
  "connections": [
    {
      "port": 51871,
      "host": "localhost"
    }
  ],
  "plugins": {
    "visionary": {
      "engines": { "html": "handlebars" },
      "path": "./lib/templates",
      "layout": true
    },
    "exampleHome": null
  }
}

initialize npm for project

npm init

install dependencies

npm install --save rejoice handlebars visionary

package.json for project

add "start" to scripts:

  "scripts": {
    "start": "node node_modules/rejoice/bin/rejoice -c config/manifest.json"
  }

add home module to dependencies:

(There will be other dependencies, don't remove them - not listing them here for brevity)

  "dependencies": {
    "exampleHome": "./lib/modules/home"
  }

Note: exampleHome is specifying the local directory that contains the plugin, if you do this you need to npm install each time you make changes to it. This could alternatively be a git repository for true modularization of sections, or an npm published module (private or public NPM, whatever makes sense)

install local home module via npm

npm install

starting the server

npm start

Fire up http://localhost:51871 and see it in action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment