2.0.0 • Published 7 years ago

nunjucks-browsersync-server v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

nunjucks-browsersync-server

Easily create and configure a browser-sync + nunjucks server for serving static pages on the fly during template development

Installation

npm install nunjucks-browsersync-server

API

server

Server module

server.start(config)

Start a nunjucks-browsersync-server instance

Kind: static method of server

ParamTypeDefaultDescription
configObject
config.staticPathStringA path containing static assets you want to serve along with your nunjucks pages
config.basePortNumber8020The port you want the server to start looking for available ports to serve on. The browser-sync ui server will start on the next port after the one that the server starts on
config.nunjucksObjectAn object of nunjucks configuration options
config.nunjucks.rootstringThe root path where your nunjucks files are
config.nunjucks.renderPathstringThe folder name of the pages folder you want to render on the server. Is also used to match the urls under which you want nunjucks to render
config.nunjucks.datafunctionA function returning the data you want to pass to the nunjucks templates
config.nunjucks.globalsObjectAny other nunjucks globals you want to add
config.nunjucks.extensionstring"'.njk'"The extension to match for nunjucks files
config.nunjucks.configureEnvfunctionA function that exposes the nunjucks environment instance in order to directly manipulate it if necessary
config.browserSyncObjectbrowser-sync configuration optiosn to mix with the defaults. See browser-sync docs.

Example

// Imagine a directory structure
// - assets
// - html
// -- pages
// --- page-1.njk
// -- layouts
// -- partials
// -- data.json

var server = require('nunjucks-browsersync-server')

server.start({
  staticPath: './assets',
  browsersync: {
    files: ['./assets/**', './html/**']
  },
  nunjucks: {
    root: './html',
    renderPath: 'pages',
    globals: require('../nunjucks'),
    data: require('./html/data.json')
  }
})

// Now you can go to localhost:8020/pages/page-1.html and it will render the nunjucks page at './html/pages/page-1.njk' on the fly

Contributing to nunjucks-browsersync-server

Standard JS applies

camelCase for function and variable names

Github Flow - branch, submit pull requests

Getting set up

  • Pull the repo
  • run npm install
  • run gulp to build from index.es6.js to the compiled index.js file