0

Filesystem ローダーを次のように拡張するだけです。

var nunjucks = require('nunjucks');

MyLoader = nunjucks.FileSystemLoader.extend({

        getSource: function(name) {

            return this.parent().getSource(name);
        }

 });

私がいつも得る方法:

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:8:11)
    at Object.posix.resolve (path.js:426:5)
    at Loader.extend.getSource (/home/myname/myapp/node_modules/nunjucks/src/node-loaders.js:60:26

getSource親メソッドを正しく呼び出す方法は?

助けてください。ありがとう

4

1 に答える 1

0
var CustomLoader = nunjucks.FileSystemLoader.extend({
    getSource: function(name) {
        var result = nunjucks.FileSystemLoader.prototype.getSource.call(this, name); // !!!

        if (!result) 
            return null;

        result.src = ... // do-smth-with-content
        return result;
    }
}); 

var env = new nunjucks.Environment(
    new CustomLoader([your-template-paths], { watch: false, noCache: false }), 
    {autoescape: true});
env.express(app); // don't forget connect to express

詳細については、github (nunjucks-minify-loaders) を参照してください。

于 2016-08-29T16:56:44.970 に答える