From 6ec25f4e432e25432e8bef3a9bdc6ba86cfc50e6 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Mon, 19 Sep 2011 03:17:15 +0000 Subject: [PATCH] Update to function with latest version of build system. --- profiles/main.profile.js | 37 ++++++++++++++++++++++++++++++++++--- src/index.html | 2 +- src/js/boot.js | 28 ++++++++++++++++++++++++++++ src/server.sh | 2 +- util/build.sh | 6 ++++-- 5 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/js/boot.js diff --git a/profiles/main.profile.js b/profiles/main.profile.js index c6eaf6f..2a41b26 100644 --- a/profiles/main.profile.js +++ b/profiles/main.profile.js @@ -1,16 +1,44 @@ +/** + * Build profiles look mostly the same in Dojo 1.7 as they do in previous versions of the toolkit. + */ dependencies = { + // First cleans the dist directory of existing code, then builds a new release. action: 'clean,release', - async: true, + + // Strips all comments from CSS files. cssOptimize: 'comments', + + // Excludes tests, demos, and original template files from being included in the built version. mini: true, + + // Uses ShrinkSafe as the JavaScript minifier. This can also be set to "closure" to use Closure Compiler. optimize: 'shrinksafe', + + // This is the directory within the output directory that built JavaScript will be placed. releaseName: 'js', + + // Strips all calls to console functions within the code. stripConsole: 'all', + // Builds can be split into multiple different JavaScript files called "layers". This allows applications to + // defer loading large sections of code until they are actually required. Note that, at the moment, module IDs + // in "dependencies" are still written using dots instead of slashes. layers: [ - { name: '../app/_base.js', resourceName: 'app._base', dependencies: [ 'app._base', 'app.main' ] } + // The default selector engine is not included by default in a dojo.js build in order to make mobile builds + // smaller. We add it back here to avoid that extra HTTP request. + { name: 'dojo.js', dependencies: [ 'dojo.selector.acme' ] }, + + // This is our main application layer. This layer will normally contain most or all of your application code. + { name: '../app/main.js', dependencies: [ 'app.main' ] }, + + // In the demo application, we conditionally require app/Dialog on the client-side, so we're building a + // separate layer containing just that client-side code. + { name: '../app/Dialog.js', dependencies: [ 'app.Dialog' ] } ], + // Each package requires a defined prefix so that the builder can find and combine modules into a single file. + // The first string in each array is the package name, and the second string is the path to that package, relative + // to the directory containing dojo.js. prefixes: [ [ 'dijit', '../dijit' ], [ 'dojox', '../dojox' ], @@ -18,7 +46,10 @@ dependencies = { [ 'dbp', '../dbp' ] ], + // Providing hints to the build system allows code to be conditionally removed on a more granular level than + // simple module dependencies can allow. This is especially useful for creating tiny mobile builds. + // Keep in mind that dead code removal only happens in minifiers that support it! Currently, ShrinkSafe does not + // support dead code removal; Closure Compiler and UglifyJS do. staticHasFeatures: { - 'dojo-sync-loader':0 } } \ No newline at end of file diff --git a/src/index.html b/src/index.html index 69bab22..58da7b1 100644 --- a/src/index.html +++ b/src/index.html @@ -28,6 +28,6 @@ src="js/dojo/dojo.js" defer> - + \ No newline at end of file diff --git a/src/js/boot.js b/src/js/boot.js new file mode 100644 index 0000000..a675031 --- /dev/null +++ b/src/js/boot.js @@ -0,0 +1,28 @@ +/** + * This file is used to reconfigure parts of the loader at runtime for this application. We've put this extra + * configuration in a separate file, instead of adding it directly to index.html, because it contains options that + * can be shared if the application is run on both the client and the server. + * + * If you aren't planning on running your app on both the client and the server, you could easily move this + * configuration into index.html (as a dojoConfig object) if it makes your life easier. + * + * This file must remain outside of any defined package directory at the current time or it will be transformed by the + * build system into a legacy module. + */ +require({ + // The base path for all packages and modules. If you don't provide this, baseUrl defaults to the directory + // that contains dojo.js. + baseUrl: 'js/', + + // A list of packages to register. Strictly speaking, you do not need to register any packages, + // but you can't require "app" and get app/main.js if you do not register the "app" package (the loader will look + // for a module at app.js instead). Unregistered packages also cannot use the packageMap feature, which might + // be important to you if you need to relocate dependencies. + packages: [ + { name: 'dojo', location: 'dojo' }, + { name: 'dijit', location: 'dijit' }, + { name: 'dojox', location: 'dojox' }, + { name: 'app', location: 'app' }, + { name: 'dbp', location: 'dbp' } + ] +}, [ 'app' ]); \ No newline at end of file diff --git a/src/server.sh b/src/server.sh index 95f36b9..1b3a77e 100755 --- a/src/server.sh +++ b/src/server.sh @@ -3,4 +3,4 @@ # This is a very simple script that demonstrates how to load a Dojo # application on the server using Node.js. -node js/dojo/dojo.js load=app/_base +node js/dojo/dojo.js load=boot diff --git a/util/build.sh b/util/build.sh index 37c14b9..2ba763d 100755 --- a/util/build.sh +++ b/util/build.sh @@ -40,10 +40,12 @@ fi cd "$UTILDIR" +# copy the config.js file +cp "$SRCDIR/js/boot.js" "$DISTDIR/js/boot.js" + # copy the index.html and make it production-friendly cp "$SRCDIR/index.html" "$DISTDIR/index.html" -sed -i -e "s/ //" \ - -e "s/