build - 如何告诉 Dojo 构建忽略 'missing' 模板

标签 build dojo

我们的应用程序有许多小部件,它们使用通过 JSP 动态生成的模板。

在前端代码中,它们是使用 dojo/text 插件包含的。这确保了 Widget 生命周期在模板被解析之前不会启动,并且它工作得很好。

不幸的是,当我们尝试执行构建时,会收到 311 错误:

error(311) Missing dependency. module: app/navigation/NavigationManager; dependency: dojo/text!/author/app/templates/NavigationManager-content.html; error: Error: text resource (/author/app/templates/NavigationManager-content.html/x) missing



我明白这里发生了什么,构建过程试图将字符串内部化,但是当它去寻找它时,它无法找到它,因此将它标记为缺失的依赖项。

我在这里看到了许多选项:
  • 不知何故,告诉 Dojo 忽略此缺失的依赖项 - 这很好,但我需要能够具体化,以便我收到可能缺失的任何其他依赖项的警报
  • 不知何故,告诉 Dojo 不要尝试内化这个模板——这也很好,因为这里没有什么需要内化的。
  • 不知何故, stub 依赖,以便依赖解析通过,但不会发生内化。

  • 我看过引用资料
    实习生字符串跳过列表
    值(value),但以下没有任何帮助:
    internStringsSkipList: ['/author/pepper/templates/NavigationManager-content.html']
    internStringsSkipList: ['dojo/text!/author/pepper/templates/NavigationManager-content.html']
    internStringsSkipList: ['/author/pepper/templates/NavigationManager-content.html/x']
    

    有什么建议?

    最佳答案

    我遇到了完全相同的问题,在阅读了大量 dojo 文档和源代码后,我得出的结论是,如果几乎不可能做到,这非常困难。但是,有一个非常简单和优雅的解决方法。但在告诉您如何解决问题之前,首先为什么需要解决方法(以便您可以根据自己的情况调整解决方案):
    第一个问题,资源不可发现
    根据道场构建系统的概述部分Reference Guide :

    [The build system] “discovers” a set of resources and then applies a synchronized, ordered set of resource-dependent transforms to those resources. (…) When a resource is discovered, it is tagged with one or more flags that help identify the role of that resource. (…) After a resource is discovered and tagged, the system assigns a set of transforms that are to be applied to that resource.


    简而言之,构建系统无法发现任何动态生成的资源,因为它们不驻留在文件系统中。如果它们不能被发现,那么它们就不能被标记并且不能对其应用任何转换。特别是resourceTags不需要此类资源,您不能将它们放在 exclude 上。剖面层定义列表(比较 Creating Builds 中的层部分)。
    顺便说一句,据我所知 documentation to depsScan transform , internStringsSkipList只能用于跳过使用遗留符号( dojo.something ,例如 dojo.moduleUrl )指定的资源。
    第二个问题,插件解析器需要一个物理文件
    符号dojo/text!/some/url说要使用 dojo/text.js组件作为插件。我在 this ticket 中找到了这个笔记:

    Every AMD plugin should have a plugin resolver in util/build/plugins and have it registered in util/build/buildControlDefault.


    如果您检查 util/build/plugins/text.js (例如 on Github )你会看到错误被抛出,因为依赖(在 dojo/text! 之后的那部分存储在 moduleInfo 中)不在 resources 中大批:
    textResource = bc.resources[moduleInfo.url];
    if (!textResource){
      throw new Error("text resource (" + moduleInfo.url + ") missing");
    }
    
    而这正是因为在“发现”阶段无法发现资源。
    困难的解决方案
    在困难的解决方案中,这可能有效也可能无效,您需要更改转换方式 depsScan作品。基本上,当 depsScan遭遇dojo/text!/some/url它调用插件解析器来检查依赖项是否存在。来自 depsScan documentation :

    Once all dependencies are found, the transform ensures all dependencies exist in the discovered modules. Missing dependencies result in an error being logged to the console and the build report.


    这可能通过重新定义 transformJobs 来实现包含 depsScan 的自定义变换.见 util/build/buildControlDefault.js ( on Github ) 和 this forum post了解更多信息。
    简单的解决方法
    只需创建自己的插件来加载资源。你自己的插件不会注册插件解析器(见上面的第二个问题),编译时你会得到的只是可怕的warn(224) A plugin dependency was encountered but there was no build-time plugin resolver.这是我动态加载 JSON 资源的此类插件的示例:
    define(["dojo/text", "dojo/_base/lang", "dojo/json"],
    function(text,lang,json){
      return lang.delegate(text, {
        load: function(id, require, load){
          text.load(id, require, function(data){
            load(json.parse(data));
          });
        }
      });
    });
    
    它重复使用 dojo/text添加其自定义加载功能。这是对发布在 this dojo-toolkit forum post 上的另一个示例的改编。 .你可以在 JSFiddle 上看到他们的代码.
    在我的项目中,我使用这样的插件:
    define(["./json!/path/to/an/json"],
    function(values){
      return values;
    });
    
    您的插件可以只返回加载的模板而不将其解析为 JSON,只要您不指定自定义插件解析器(它希望文件物理存在于磁盘上),项目就可以正常编译。

    关于build - 如何告诉 Dojo 构建忽略 'missing' 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16283443/

    相关文章:

    version-control - 在您的源代码树中,自定义构建工具在哪里?

    javascript - dijit/form/Select 在使用 Esri Javascript 3.7 的 Internet Explorer 中损坏

    javascript - Dojo 1.6 - 设置 Dijit.Select 按标签选择

    javascript - 在 dojo NumberTextBox 中输入非数字字符时布局被更改

    javascript - 修改 wm.Number 编辑器小部件上的 rangeMes​​sage

    c++ - 构建失败错误 : Cannot build C++ SDK Helloworld with qibuild

    delphi - 即使某个项目编译失败,如何尝试构建项目组中的所有项目

    maven - 以交互模式生成项目花费大量时间

    build - 在 gemfury 中覆盖/强制推送现有的包版本

    javascript - 使 dijit.form.currencytextbox 接受小数点后一位数字的负值