道场的最低构建配置是什么样的



我研究了构建教程,找到了 Web 构建(仅限 1.7.2),并测试了几个示例 - 但是,我找不到构建系统的简单解释。

假设我的应用是单个网页:

<script src="./js/App/other_non_amd_stuff_working_independently.js">
<script src="./js/lib/dojo/dojo.js" data-dojo-config="async: true"></script>
<script src="./js/App/Main.js">

Dojo SDK 位于 ./lib/中,主.js包含 Dojo 配置 + app boot:

require({
    packages:[{
        name:"App",
        location:"../../App"
    }]
},  
[ "dojo/query",
  "dijit/layout/BorderContainer", 
  "App/Foo",
  "dojo/domReady!"], function(query, BorderContainer, Foo) { ... });

我现在的问题很简单:如何从我所有的 Dojo/AMD 内容中创建一个脚本文件?我只想替换

<script src="./js/lib/dojo/dojo.js" data-dojo-config="async: true"></script>
<script src="./js/App/Main.js">

与单

<script src="./js/Main.minified.js">

让构建系统对此工作似乎有些不平凡。它要么尝试将./App/中的所有文件转换为AMD模块(这不是我想要的..),要么找不到App/Main。我尝试构建一个构建配置文件(app.profile.js),但我不明白这一点,除了它增加了(IMO 不必要的)复杂性。如何使构建系统仅连接我的应用程序/主.js包括依赖项?

任何关于理解构建系统的更好教程的提示也值得赞赏。

请参阅此 QnA 以将图层构建到 dojo.js 文件中。我不妨分享我的经验,因为我需要一些试验和错误才能让我的引导正常工作。实际上,答案很容易在'dojosdk/util/buildscripts/profiles/baseplus.profile.js"文件中找到。

Dojo 自定义构建 1.6 到单个文件中(与新构建系统相同的设置,但 2.0 可能仍会进行一些更改)

如何创建与道场缝合在一起的主应用层.js

dependencies ={
  layers:  [
      {
      name: "dojo.js", // overwrites regular dojo.js and ++'s your layer
      dependencies: [
         "app.main"
      ]
  }
}

请记住正确添加位置前缀

由于您将"应用程序"模块放置在 dojo SDK 根目录之外,因此当您在 dojoConfig 中分配packages时,也需要应用相同的模块。但是,属性键prefixes用于图层配置文件。

prefixes: [
    [ "dijit", "../dijit" ],
    [ "dojox", "../dojox" ],
    [ "App", "../../App" ]
]

如何创建子模块层

您可能希望构建应用程序的子模块,以便例如弹出对话框需要额外的额外内容 - 可以在运行时将它们下载到单独的包中。为了确保通过模块层加载的依赖项不包含在子模块层中,您要查找的属性键是 layerDependencies

对于组合结果,它看起来像这样:

dependencies ={
  layers:  [
      {
        name: "../dojo/dojo.js", // overwrites regular dojo.js and ++'s your layer
        dependencies: [
         "app.Main"
        ]
      }, {
        name: "../../App/JITModule.js",
        layerDependencies: [
         "../../App/Main"   // tells this layer that the dependencychain in Main is allready loaded (programmer must make sure this is true ofc)
        ]
        dependencies: [
         "App.JustInTimeDialog"
        ]
      }
  ]
  prefixes: [
    [ "dijit", "../dijit" ],
    [ "dojox", "../dojox" ],
    [ "App", "../../App" ]
  ]
}

这应该会产生两个优化的图层文件,一个具有标准的单行道.js加上一个 dojo.cache 条目,其中包含应用程序中的文件。请注意,您仍然需要为任何缓存的模块调用require,否则它们将仅保留在缓存中。

在 HTML 中将其放在一起

注意 将 dojoConfig 放入 ./js/App/Main.js 文件将无法按预期工作,dojo.js常规内容加载到图层上方。

<head>
  <script>
     function JITDialog() {
          require([ "App.JITDialog" ], function(dialoglayer)  {
             var dialog = new App.JustInTimeDialog();
             dialog.show();
          });
     }
     var dojoConfig = {
         async: true,
         packages:[{
            name:"App",
            location:"../../App"
         }]
     }
  </script>
  <script src="./js/lib/dojo/dojo.js"></script>
  <script>    
     require("App.Main", function() {
        // loads the layer, depending on the structure of App.Main class,
        // you can call your initializations here
        var app = new App.Main();
        app.run();
     });
  </script>
</head>
<body>
  <button onclick="JITDialog();">
      Download sub-module-layer and show a dialog on user interaction
  </button>
</body>

最新更新