Permalink
Browse files

Fixed a bug when setting an 'out' property in your requirejs config. …

…fix #3
  • Loading branch information...
1 parent 20ada82 commit 52096b00d5b56d40b4fb4f5057090471206a4523 @asciidisco committed May 21, 2012
Showing with 64 additions and 23 deletions.
  1. +2 −2 .gitignore
  2. +1 −1 .npmignore
  3. +24 −1 README.md
  4. +25 −0 grunt.js
  5. +1 −1 package.json
  6. +11 −18 tasks/require.js
View
@@ -1,2 +1,2 @@
-
-.DS_Store
+/node_modules/
+.DS_Store
View
@@ -1 +1 @@
-/node_modules/
+/node_modules/
View
@@ -72,7 +72,6 @@ The only constraint for using the auto almond insertion is, that you at least de
(mostly named 'main').
```javascript
-
// ... grunt file contents
requirejs: {
// almond specific contents
@@ -106,7 +105,31 @@ The only constraint for using the auto almond insertion is, that you at least de
// ... even more grunt file contents
```
+### Special case, the 'out' property
+
+If you define a special output name for your generated module file,
+you have to specify a "modulePath" property inside your "replaceRequireScript" configuration
+```javascript
+requirejs: {
+ almond: true,
+ replaceRequireScript: [{
+ files: ['index.html'],
+ module: 'main',
+ modulePath: '/js/main-build'
+ }],
+ baseUrl: "js",
+ paths: {
+ 'Handlebars': 'libs/Handlebars',
+ 'Backbone': 'libs/backbone',
+ 'underscore': 'libs/underscore',
+ 'json2': 'libs/json2',
+ },
+ modules: [{name: 'main'}],
+ out: 'js/main-build.js'
+}
+```
+
## Dual Config
By default it is assumed that your are using the optimizer for only JS or CSS not both. However should you wish to use require.js to optimize your CSS in addition to your JS, this is possible using a dual config. This will allow you to maintain your config options for both your CSS and JS under the requirejs key in your grunt.js.
View
@@ -2,6 +2,31 @@ module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
+ pkg: '<json:package.json>',
+ meta: {
+ banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n' +
+ '------------------------------\n' +
+ 'Build @ <%= grunt.template.today("yyyy-mm-dd") %>\n' +
+ 'Documentation and Full License Available at:\n' +
+ '<%= pkg.homepage %>\n' +
+ '<%= pkg.repository.url %>\n' +
+ 'Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n\n' +
+ 'Permission is hereby granted, free of charge, to any person obtaining a\n' +
+ 'copy of this software and associated documentation files (the "Software"),\n' +
+ 'to deal in the Software without restriction, including without limitation\n' +
+ 'the rights to use, copy, modify, merge, publish, distribute, sublicense,\n' +
+ 'and/or sell copies of the Software, and to permit persons to whom the\n\n' +
+ 'Software is furnished to do so, subject to the following conditions:\n' +
+ 'The above copyright notice and this permission notice shall be included in\n' +
+ 'all copies or substantial portions of the Software.\n\n' +
+ 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\n' +
+ 'EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n' +
+ 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n' +
+ 'IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n' +
+ 'DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n' +
+ 'ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n' +
+ 'IN THE SOFTWARE.*/'
+ },
test: {
files: ['test/**/*.js']
},
View
@@ -1,7 +1,7 @@
{
"name": "grunt-requirejs",
"description": "Using requirejs and almond with grunt",
- "version": "0.2.5",
+ "version": "0.2.6",
"homepage": "https://github.com/asciidisco/grunt-requirejs",
"author": {
"name": "asciidisco",
View
@@ -6,9 +6,7 @@
* Licensed under the MIT license.
*/
-module.exports = function (grunt) {
- 'use strict';
-
+module.exports = function(grunt) {
// Grunt utilities.
var task = grunt.task;
var file = grunt.file;
@@ -17,6 +15,7 @@ module.exports = function (grunt) {
var fail = grunt.fail;
var config = grunt.config;
var utils = typeof grunt.utils !== 'undefined' ? grunt.utils : grunt.util;
+ var _ = utils._;
// shortcuts
var isArray = utils._.isArray;
@@ -41,7 +40,7 @@ module.exports = function (grunt) {
done: done,
cb: cb
});
- };
+ }
};
// runs the almond js html file replacement
@@ -52,7 +51,7 @@ module.exports = function (grunt) {
done: done,
cb: cb
});
- };
+ }
};
// ==========================================================================
@@ -93,11 +92,11 @@ module.exports = function (grunt) {
log.ok('RequireJS optimizer finished');
// display sizes of modules
- if (isArray(options.config.modules) && options.config.dir && options.config.baseUrl) {
+ if (isArray(options.config.modules) && options.config.baseUrl) {
options.config.modules.forEach(function (module) {
try {
// Query the entry
- var stats = fs.lstatSync(module._buildPath);
+ stats = fs.lstatSync(module._buildPath);
// Is it a file
if (stats.isFile()) {
@@ -145,7 +144,8 @@ module.exports = function (grunt) {
// replace the attributes of requires script tag
// with the 'almonded' version of the module
var $newElm = $(elm).clone(), newElm = $newElm[0].outerHTML;
- contents = contents.replace($.trim(newElm.replace('<script', '').replace('></script>', '')), 'src="' + $newElm.attr('data-main') + '.js"');
+ var insertScript = _.isUndefined(entry.modulePath) !== true ? entry.modulePath : $newElm.attr('data-main');
+ contents = contents.replace($.trim(newElm.replace('<script', '').replace('></script>', '')), 'src="' + insertScript + '.js"');
}
});
@@ -228,17 +228,10 @@ module.exports = function (grunt) {
}
});
- // Output some size info about the generated module
+ // Output some size info about a file.
grunt.registerHelper('require_size_info', function(module, optimized, filecontents) {
- var gzipSize = grunt.helper('gzip', filecontents).length,
- fileSize = filecontents.length,
- message = 'Compressed size for module "' + module + '": ' + String(gzipSize).green + ' bytes gzipped (' + String(fileSize).green + ' bytes ' + (optimized !== false ? 'minified' : 'uncompressed') + ').';
-
- // output info msg
- grunt.log.writeln(message);
-
- // return traced informations
- return {gzipSize: gzipSize, module: module, fileSize: fileSize, message: message};
+ var gzipSize = String(grunt.helper('gzip', filecontents).length);
+ grunt.log.writeln('Compressed size for module "' + module + '": ' + gzipSize.green + ' bytes gzipped (' + String(filecontents.length).green + ' bytes ' + (!!optimized !== false ? 'minified' : 'uncompressed') + ').');
});
};

0 comments on commit 52096b0

Please sign in to comment.