Avoiding redundancies in the Dojo build process

So, for our major (full site) project we are using the Dojo Toolkit. We have a build script that is condensing and compressing the JavaScript files using the Dojo build architecture. Each site page uses a global set of scripts for general utilities and ui, and then usually has another set of script for specific widgets and such.

It took me a while to find how to write the build script to omit duplicate dependencies included in the global but required by the page-specific scripts. For instance, we have a custom form handler called MyProject.form and is extended by page-specific classes. So, with the original build this class was included in the Global layer and the page-specific layer resulting in the MyProject.form class being in both .js files in the built page.

The answer is: layerDependencies in the build script.

dependencies = {
    resourceName: "MyProject",
    layers: [
    {
        name: "../../MyProject/Global.js",
        dependencies: ["MyProject", "MyProject.Global"]
    },
    {
        name: "../../MyProject/CategoryPage.js",
        dependencies: ["MyProject.CategoryPage"],
        layerDependencies: ["../../MyProject/Global.js"]
    }
    ]
};

So,  if a class in dojo.required (and therefore included) in Global.js it will be not be copied into CategoryPage.js if it is required there, also.

Tags: , , ,

This entry was posted on Monday, January 5th, 2009 at 1:23 pm by josephsong, filed under Development, JavaScript. You can follow any responses to this entry through the RSS 2.0 feed.You can leave a response, or trackback from your own site.

One Response to “Avoiding redundancies in the Dojo build process”

  1. Xang Xiong says:

    Wow, thanks. I was just looking for this. Definitely will help me greatly.

Leave a Reply