diff --git a/build/example.build.js b/build/example.build.js index a8500a9b..47657fe2 100644 --- a/build/example.build.js +++ b/build/example.build.js @@ -113,11 +113,49 @@ //excludeStart/excludeEnd and includeStart/includeEnd work, and the //the pragmas value to the includeStart or excludeStart lines //is evaluated to see if the code between the Start and End pragma - //lines should be included or excluded. + //lines should be included or excluded. If you have a choice to use + //"has" code or pragmas, use "has" code instead. Pragmas are harder + //to read, but they can be a bit more flexible on code removal vs. + //has-based code, which must follow JavaScript language rules. + //Pragmas also remove code in non-minified source, where has branch + //trimming is only done if the code is minified via UglifyJS or + //Closure Compiler. pragmas: { fooExclude: true }, + //Same as "pragmas", but only applied once during the file save phase + //of an optimization. "pragmas" are applied both during the dependency + //mapping and file saving phases on an optimization. Some pragmas + //should not be processed during the dependency mapping phase of an + //operation, such as the pragma in the CoffeeScript loader plugin, + //which wants the CoffeeScript compiler during the dependency mapping + //phase, but once files are saved as plain JavaScript, the CoffeeScript + //compiler is no longer needed. In that case, pragmasOnSave would be used + //to exclude the compiler code during the save phase. + pragmasOnSave: { + //Just an example + excludeCoffeeScript: true + }, + + //Allows trimming of code branches that use has.js-based feature detection: + //https://github.com/phiggins42/has.js + //The code branch trimming only happens if minification with UglifyJS or + //Closure Compiler is done. For more information, see: + //http://requirejs.org/docs/optimization.html#hasjs + has: { + 'function-bind': true, + 'string-trim': false + }, + + //Similar to pragmasOnSave, but for has tests -- only applied during the + //file save phase of optimization, where "has" is applied to both + //dependency mapping and file save phases. + hasOnSave: { + 'function-bind': true, + 'string-trim': false + }, + //Allows namespacing requirejs, require and define calls to a new name. //This allows stronger assurances of getting a module space that will //not interfere with others using a define/require AMD-based module diff --git a/build/tests/httpBuild.js b/build/tests/http/httpBuild.js similarity index 55% rename from build/tests/httpBuild.js rename to build/tests/http/httpBuild.js index 04c5f39e..16e74f54 100644 --- a/build/tests/httpBuild.js +++ b/build/tests/http/httpBuild.js @@ -1,7 +1,8 @@ /*jslint strict: false*/ /*global require: false, console: false */ -var requirejs = require('../../r.js'), +//If you install requirejs via npm, replace this line with require('requirejs') +var requirejs = require('../../../r.js'), http = require('http'), fs = require('fs'), host = '127.0.0.1', @@ -10,11 +11,27 @@ var requirejs = require('../../r.js'), //Set up the config passed to the optimizer config = { - baseUrl: '../../../requirejs/tests', + baseUrl: 'scripts', + paths: { + //Put path to require.js in here, leaving off .js + //since it is a module ID path mapping. For final deployment, + //if a smaller AMD loader is desired, no dynamic + //loading needs to be done, and loader plugins are not + //in use, change this path to that file. One possibility + //could be the one at: + //https://github.com/ajaxorg/ace/blob/master/build_support/mini_require.js + requireLib: '../../../../../requirejs/require' + }, + //Uncomment this line if uglify minification is not wanted. //optimize: 'none', - name: 'one', - include: 'dimple', - out: 'builds/outSingleOpt.js' + //Specify the optimization target. Choose the requireLib, + //so that it is first in the output, then include the main.js + //for this project. + name: 'requireLib', + include: ['main'], + //Uncomment this if you want to debug three.js by itself + //excludeShallow: ['three'], + out: 'scripts/main-built.js' }; function respond(res, code, contents) { diff --git a/build/tests/http/main.html b/build/tests/http/main.html new file mode 100644 index 00000000..3186149c --- /dev/null +++ b/build/tests/http/main.html @@ -0,0 +1,28 @@ + + +
+Be sure to start up the server: node httpBuild.js
+ +Demonstrates how to use the RequireJS optimizer to only load + one script in the page using Node as the server to serve the optimized + script. Using the "excludeShallow" build config option inside httpBuild.js + allows debugging one script separate from the rest of the optimized file.
+ +See httpBuild.js in the same directory as this file for more information.
+ +