2.0.0 • Published 7 years ago

fileloader v2.0.0

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

fileloader

NPM version build status Test coverage David deps npm download

more stable file loader for nunjucks, and support charsets like gbk.

Install

$ npm install fileloader

Usage

const nunjucks = require('nunjucks');
const FileLoader = require('fileloader');
const cluster = require('cluster');

let watch = true;
if (cluster.isWorker) {
  watch = function(dirs, listener) {
    process.on('message', msg => {
      if (msg && msg.action === 'watch-file') {
        console.warn('got master file change message: %j', msg.info);
        listener(msg.info);
      }
    });
  };
}

const dirs = ['/foo', '/bar/cms'];
const charsets = {
  '/bar/cms': 'gbk'
};

const fileloader = new FileLoader(dirs, watch, charsets);
const env = new nunjucks.Environment(fileloader);

License

MIT