0

我对花椰菜还很陌生,一直在尝试编写一个简单的插件来与 ember.js 一起使用。我在 index.js 中使用了 broccoli-caching-writer,如 broccoli-caching-writer 的 github 页面上所述:

var CachingWriter = require('broccoli-caching-writer');


module.exports = CachingWriter.extend({
    init: function(inputTrees, options)
    {   
        console.log('Initializing plugin with tree');
        console.log(inputTrees);
        console.log(options);
        this.inputTrees = inputTrees;

    },
    updateCache: function(srcPaths, destDir) {
        console.log('updateCache called with srcPaths and destDir');
        console.log(srcPaths);
        console.log(destDir);
    }
});

然后我将插件导入我的 ember 应用程序(使用 ember CLI)并在我的 .brocfile 中配置以下内容

var plugin = require('broccoli-my-plugin');
var merge = require('broccoli-merge-trees');

pluginTree = new svgSpriter(['images'], {some: 'options'});
....
....
module.exports = merge([app.toTree(),pluginTree]);

使用 ember build 命令运行上述命令会得到以下输出(出于隐私原因编辑的路径):

    Build failed.
Cannot read property 'images/.DS_Store' of undefined
TypeError: Cannot read property 'images/.DS_Store' of undefined
    at CoreObject.proto.shouldBeIgnored (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/index.js:135:33)
    at CoreObject.proto.keyForTree (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/index.js:277:14)
    at CoreObject.<anonymous> (/node_modules/broccoli-caching-writer/index.js:267:21)
    at Array.map (native)
    at CoreObject.proto.keyForTree (/node_modules/broccoli-caching-writer/index.js:266:24)
    at /node_modules/broccoli-caching-writer/index.js:87:20
    at lib$rsvp$$internal$$tryCatch (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:489:16)
    at lib$rsvp$$internal$$invokeCallback (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:501:17)
    at lib$rsvp$$internal$$publish (/node_modules/broccoli-svg-sprite/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:472:11)
    at lib$rsvp$asap$$flush (/node_modules/broccoli-caching-writer/node_modules/rsvp/dist/rsvp.js:1290:9)

似乎插件正在尝试检查是否忽略路径,但是传递给缓存编写器的选项没有定义 filterfromcache 选项,所以上面应该有效吗?不确定我是否遗漏了什么?

任何帮助,将不胜感激。

4

1 回答 1

0

好的,我认为重写 init 方法的示例需要对像我这样的新手进行一些更新。事实证明,父模块中的 init 方法没有被调用。将以下内容添加到我的 init 方法中修复了它:

      CachingWriter.prototype.init.call(this, inputTrees, options);

虽然不确定是否有更好的方法。

于 2015-06-11T20:00:30.073 回答