【问题标题】:What's the best way to find all assets in a meteor application?在流星应用程序中查找所有资产的最佳方法是什么?
【发布时间】:2013-12-08 16:54:17
【问题描述】:

我知道可以只读取 program.json 文件,其中列出了所有资产: https://github.com/meteor/meteor/issues/1328#issuecomment-22913769

但是这种感觉是错误的,我不知道这是否会得到支持。在这方面,关于资产本身的文档仍然有些稀疏 (http://docs.meteor.com/#assets)。

是否有关于如何列出所有资产的最佳做法?

【问题讨论】:

  • 那么,你找到解决办法了吗?
  • 不,还没有。有什么想法吗?

标签: meteor


【解决方案1】:

我不知道这是否是最佳实践,但我通过使用流星包https://github.com/peerlibrary/meteor-fs(它是https://nodejs.org/api/fs.html 的薄包装)并进行了一些探索,从而实现了大部分目标。结果这些资产被放入了一个名为app/的文件夹中。

我的代码如下所示:

if (Meteor.isServer) {
    Meteor.startup(function() {
        // clear database and load everything in the articles folder
        fs.readdir("assets/app/", function(err, files) {
            if (err) throw err;
            files.forEach(function (val, ind, arr) {
                console.log(val);
            });
        });
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多