【问题标题】:What is the right way to share a jade template to other modules将翡翠模板共享给其他模块的正确方法是什么
【发布时间】:2015-05-08 06:41:28
【问题描述】:

所以我开始使用节点和玉模板生成纸牌游戏原型 pdf 的项目。为了使该项目对其他人更有用,我正在考虑尝试在我的模块中将几个翡翠模板打包为标准卡片布局,用户可以根据他们的特定需求进行扩展。这种方法的问题是,我真的想不出一个好方法来让他们的翡翠模板扩展我的翡翠模板,而不需要对 node_modules 文件进行一些非常麻烦的访问。有没有更好的办法?

【问题讨论】:

    标签: node.js npm pug


    【解决方案1】:

    您可以从节点模块中导出模板集合。

    假设你的模块叫做“tpl-cards”,那么你可以这样做:

    module.exports = {
      main_lib: function() {
        /* your main lib */
      },
      templates: [
        /* list of templates */
      ]
    }
    

    那么您的用户可以这样做:

    var templates = require('tpl-cards').templates;
    

    【讨论】:

    • 抱歉我的无知,但我对此有几个问题:1)我的模板列表中实际包含什么?字符串?预编译模板? 2) 扩展机制看起来像是使用相对文件路径 - 我如何扩展我以这种方式导入的内容?
    猜你喜欢
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 2016-12-25
    • 2013-05-19
    • 1970-01-01
    • 2013-06-15
    相关资源
    最近更新 更多