1

Maybe I'm just stupid, but I can't understand this article at all: https://dojotoolkit.org/documentation/tutorials/1.10/build/

Is there a working example or better article anywhere? I am to the point of googling other RequireJS-based build tools with better instructions. I was able to get r.js going in about 15 minutes, but it doesn't seem to work with dojo.

My project has the following file structure:

  • dojo
  • dijit
  • dojox
  • app (contains all custom AMD modules for this app)
  • lib (non-AMD js files)
  • main.js (main startup file)
  • app.profile.js
  • package.json

I just want to concatenate main.js, everything in app, and any dojo modules I am using into a single file. Shouldn't be too difficult! But it just copies every JS file in the release folder, and that's it. It doesn't seem to concatenate anything.

Here is my app.profile.js:

var profile = (function(){
    var copyOnly = function(filename, mid) {
            var list = {
                "./app.profile": true,
                "./package.json": true
            };
            return (mid in list) ||
                /^\.\/lib\//.test(filename) ||
                /(png|jpg|jpeg|gif|tiff|html)$/.test(filename);
        };


    return {
        basePath: "./",
        releaseDir: "./build",
        releaseName: "prod",
        action: "release",
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        mini: true,
        stripConsole: "warn",
        selectorEngine: "lite",

        packages:[{
            name: "dojo",
            location: "dojo"
        },{
            name: "dijit",
            location: "dijit"
        },{
            name: "dojox",
            location: "dojox"
        },{
            name: "app",
            location: "app"
        }],

        layers: {
            "dojo/dojo": {
                include: [ "dojo/dojo", "main" ],
                customBase: true,
                boot: true
            }
        },

        resourceTags: {
            copyOnly: function(filename, mid) {
                return copyOnly(filename, mid);
            },
            amd: function(filename, mid) {
                return !copyOnly(filename, mid) &&
                        /\.js$/.test(filename);
            }
        }
    };
})();
wmakley
  • 1,233
  • 9
  • 18
  • You have `"main"` listed in your layer but you probably meant `"app/main"`. `build-report.txt` probably has an error looking for a `main` package. Other than that, this should conceptually work. Fix that `include`, try the build again, and look at `dojo/dojo.js` or `dojo/dojo.js.uncompressed.js`. – Ken Franqueiro Oct 02 '15 at 20:19
  • main.js is the file I was previously using to boot the app, and it is in the root directory. It is a short script that requires app/Application (and some other objects), and instantiates the Application instance, then tells Application to start (which parses the dojo widgets etc). Maybe this is wrong? The problem is I have NO IDEA what defining a layer is actually telling the compiler to do. – wmakley Oct 02 '15 at 21:15
  • Defining a layer is what tells the build tool to concatenate several modules together. The things in `include` are dependencies that should be each crawled, and all of their transitive dependencies will also be included in the layer. Anyway, back to your `main` file, it might help to see that to understand what you're trying to do. Either way, the build script and loader alike can only discover modules within packages (or defined in `paths`, but `packages` is recommended). Ideally the entry point to your application would be a module that is loaded through the AMD loader like any other. – Ken Franqueiro Oct 02 '15 at 23:30

1 Answers1

0

I'm not sure what your specific problem/question is, but I have two suggestions:

  1. Here are some other (perhaps more understandable) tutorials:

  2. Google for "Dojo" "ShrinkSafe"

'Hope that helps!

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Thanks, I added specifics to my question. I followed the documentation and have a fairly complicated app.profile.js file. When I run the build tool, it just copies all the source files into the release directory, it doesn't concatenate anything. – wmakley Oct 02 '15 at 19:22
  • Shrinksafe is deprecated in favor of Closure compiler or Uglify at this point, and either way that *only* represents the minification part of the build process (i.e. `optimize` and `layerOptimize`). Also, that IBM article was written in 2011, before 1.7 and the AMD update which also deprecated several old build profile properties. – Ken Franqueiro Oct 02 '15 at 20:39