Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bluegrassdigital/nunjucks-browsersync-server

Easily create and configure a browser-sync + nunjucks server for serving static pages on the fly during template development
https://github.com/bluegrassdigital/nunjucks-browsersync-server

Last synced: 30 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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](#module_server)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| config | Object | | |
| [config.staticPath] | String | | A path containing static assets you want to serve along with your nunjucks pages |
| [config.basePort] | Number | 8020 | The 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.nunjucks | Object | | An object of nunjucks configuration options |
| config.nunjucks.root | string | | The root path where your nunjucks files are |
| config.nunjucks.renderPath | string | | The 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.data] | function | | A function returning the data you want to pass to the nunjucks templates |
| [config.nunjucks.globals] | Object | | Any other nunjucks globals you want to add |
| [config.nunjucks.extension] | string | "'.njk'" | The extension to match for nunjucks files |
| [config.nunjucks.configureEnv] | function | | A function that exposes the nunjucks environment instance in order to directly manipulate it if necessary |
| [config.browserSync] | Object | | browser-sync configuration optiosn to mix with the defaults. See browser-sync docs. |

**Example**
```js
// 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](http://standardjs.com/) applies

camelCase for function and variable names

[Github Flow](https://guides.github.com/introduction/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