Skip to content

Commit

Permalink
Build: add build option for setting the AMD name.
Browse files Browse the repository at this point in the history
Fixes #14016.
  • Loading branch information
timmywil committed Dec 19, 2013
1 parent a6f474e commit 7e8a91c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ Some example modules that can be excluded are:
- **event/alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`.
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
- **exports/amd**: Exclude the AMD definition.
- **exports/global**: Exclude the attachment of global jQuery variables ($ and jQuery) to the window.
- **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
- **deferred**: Exclude jQuery.Deferred. This also removes jQuery.Callbacks. *Note* that modules that depend on jQuery.Deferred(AJAX, effects, core/ready) will not be removed and will still expect jQuery.Deferred to be there. Include your own jQuery.Deferred implementation or exclude those modules as well (`grunt custom:-deferred,-ajax,-effects,-core/ready`).
- **exports/global**: Exclude the attachment of global jQuery variables ($ and jQuery) to the window.
- **exports/amd**: Exclude the AMD definition.

As a special case, you may also replace Sizzle by using a special flag `grunt custom:-sizzle`.

Expand All @@ -96,6 +96,22 @@ As a special case, you may also replace Sizzle by using a special flag `grunt cu

The build process shows a message for each dependent module it excludes or includes.

##### AMD name

As an option, you can set the module name for jQuery's AMD definition. By default, it is set to "jquery", which plays nicely with plugins and third-party libraries, but there may be cases where you'd like to change this. Simply set the `"amd"` option:

```bash
grunt custom --amd="custom-name"
```

Or, to define anonymously, set the name to an empty string.

```bash
grunt custom --amd=""
```

#### Custom Build Examples

To create a custom build of the latest stable version, first check out the version:

```bash
Expand All @@ -108,7 +124,7 @@ Then, make sure all Node dependencies are installed:
npm install
```

Create the custom build, use the `grunt custom` option, listing the modules to be excluded. Examples:
Create the custom build using the `grunt custom` option, listing the modules to be excluded.

Exclude all **ajax** functionality:

Expand Down
11 changes: 9 additions & 2 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = function( grunt ) {
* @param {String} contents The contents to be written (including their AMD wrappers)
*/
function convert( name, path, contents ) {
var amdName;
// Convert var modules
if ( /.\/var\//.test( path ) ) {
contents = contents
Expand All @@ -54,6 +55,12 @@ module.exports = function( grunt ) {
// Remove EXPOSE lines from Sizzle
.replace( /\/\/\s*EXPOSE[\w\W]*\/\/\s*EXPOSE/, "return Sizzle;" );

// AMD Name
} else if ( (amdName = grunt.option( "amd" )) != null && /^exports\/amd$/.test( name ) ) {
// Remove the comma for anonymous defines
contents = contents
.replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" );

} else {

// Ignore jQuery's exports (the only necessary one)
Expand Down Expand Up @@ -258,11 +265,11 @@ module.exports = function( grunt ) {
//
// grunt build:*:*:+ajax:-dimensions:-effects:-offset
grunt.registerTask( "custom", function() {
var args = [].slice.call( arguments ),
var args = this.args,
modules = args.length ? args[ 0 ].replace( /,/g, ":" ) : "";

grunt.log.writeln( "Creating custom build...\n" );

grunt.task.run([ "build:*:*:" + modules, "uglify", "dist" ]);
grunt.task.run([ "build:*:*" + (modules ? ":" + modules : ""), "uglify", "dist" ]);
});
};

0 comments on commit 7e8a91c

Please sign in to comment.