Search code examples
javascriptbuilddojoamd

Include a plain javascript file in dojo build profile


I'm building dojo 1.8.3 with a profile that puts all of dojo and my own AMD code into a single layer. I'd also like to include some non-AMD libraries (e.g. history.js) and polyfills in the same file, as-is. Is it possible to do this with the dojo build system?

The current build profile:

var profile = (function () {
var conf = {
    basePath: ".",
    layerOptimize: "closure",
    optimize: "closure",
    cssOptimize: "comments",
    mini: true,
    selectorEngine: "acme",

    defaultConfig: {
        hasCache: {
            "dojo-built": 1,
            "dojo-loader": 1,
            "dom": 1,
            "host-browser": 1,
            "config-selectorEngine": "acme"
        },
        async: 1
    },

    packages: [{
        name: "dojo",
        location: "./dojo"
    }, {
        name: "dijit",
        location: "./dijit"
    }, {
        name: "dojox",
        location: "./dojox"
    }, {
        name: "MyApp",
        location: "./MyApp"
    }, {
        name: "bootstrap",
        location: "./bootstrap"
    }],

    layers: {
        "dojo": {
            name: "dojo",
            include: [
                "dojo/dojo",
                "dojo/domReady",
                "MyApp/common",
                "MyApp/bootstrap"
            ]
        }
    }
}
return conf;
}());

Solution

  • If you add the files as a package, dojo will automatically wrap them and include them. I added this to the packages section:

    {
        name: "libs",
        location: "./libs"
    }
    

    and changed the layer definiton to:

    "dojo": {
         name: "dojo",
         include: [
             "dojo/dojo",
             "dojo/domReady",
             "libs/history/native.history",
             "libs/base64/base64",
             "MyApp/common",
             "MyApp/bootstrap"
         ]
     }    
    

    (base64 and native.history are the plain Javascript libraries)