bebraw
1/26/2011 - 11:06 AM

RequireJS alias example

RequireJS alias example

// current solution. pretty ugly. got a lot of code like this in my app :(
define(['../../utils/devices', '../../utils/math', '../../utils/paint',
        '../../configuration/configuration', '../../libs/color',
        '../../tools/tools', '../panels'],
        function(devices, math, paint, conf, color, tools, panels) {
...
}
// nicer solution
define(['devices', 'math', 'paint', 'configuration', 'color', 'tools', 'panels'],
        function(devices, math, paint, conf, color, tools, panels) {
...
}

// in this case build conf (build.js) would look something like this

{
    appDir: "my_app",
    baseUrl: "src",
    dir: "build",
    optimize: "none",

    aliases: {
        'path/to/dep': 'math', // maps to 'math' import
        ...
    }

    modules: [
        {
            "name": "main"
        }
    ]
}

// should using 'paths' prop achieve the same thing?