• function

steal.build

 

steal.build( moduleId, options )

Parameters

  1. moduleId {String}

    a JS moduleId or html page that loads steal to build. For example:

    steal.build('myapp');
    
    ./js steal/buildjs myapp
    
  2. options {Object}Optional

    An object literal with the following optional values:

    • to {String}

      The folder to put the production.js and production.css files. Ex: "myproject".

    • minify {Boolean}

      true to minify scripts, false if otherwise. Defaults to true.

    • depth {Number}
      • The total number of packages to load in production if steal.packages is used. Defaults to Infinity.
    • packageSteal {Boolean}

      true to package stealjs with production.js. Defaults to false.

      Example:

      steal.build("app",{
        minify: false,
        depth: 3.
        packageSteal: true,
        to: "staticproduction/app"
      })
      

steal.build(moduleId, options) builds a JavaScript module along with all of its dependencies. It also builds any packages specified by steal.packages.

Calling steal's build in rhino might look like:

steal.build('myproject/myproject.js',{
  to: "myproject",
  depth: 4
});

This could be run on the command-line like:

./js steal/buildjs myproject -to "myproject" -depth 4

If you used the app generator to create an application, build your project like:

./js myproject/script/build.js

Use steal.build.apps to build multiple applications at once and group shared dependencies into cache-able scripts.

Excluding code from a build.

Often, you don't want some code to be run in production. There are serveral ways to make that happen:

steal.dev.log

steal.dev.log can be used as a replacement to console.log. Steal will remove all lines that look like the following:

steal.dev.log("A message")

ignore

Use steal.config.shim to specify that a module should be ignored like:

steal.config({
  shim: {
    "mydebugtool/mydebugtool.js" : {ignore: true}
  }
})

mydebugtool/mydebugtool.js will not be loaded in production

packaged

Sometimes you don't want to include some module in production, but you still want it to load. A common case is loading jQuery from a cdn. This can be done by setting packaged to false in shim like:

steal.config({
  shim: {
    "jquery" : {packaged: false}
  },
  {
    paths: {jquery: "http://cdn.com/jquery"}
  }
})

Trouble-shooting

steal.build uses EnvJS to simulate a html page and DOM for your scripts to run inside. EnvJS is not a full featured browser and the page might not be similar to the pages your app's code runs inside. Fortunately, the fixes are easy:

__Prevent DOM manipulations, Ajax calls, or setTimeout's before onload

The easist way to do this is to surround this code with an if(steal.isRhino) like:

if( steal.isRhino ) {
  $.get("/user/current", function(){  ... })
}

Feature detect calling Canvas and other HTML5 APIs

Instead of doing:

canvas.getContext('2d');

Write

if( canvas.getContext ) {
     canvas.getContext('2d')
}

The next version of StealJS will not have this problem.