Permalink
Browse files

Generating minified files

  • Loading branch information...
1 parent 2dd18e4 commit 3546c6d729ecaa4627eaf7d0ce98c7a84bf77e1b @twolfson committed Oct 8, 2012
Showing with 10,638 additions and 5 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 README.md
  3. +1 −1 package.json
  4. +30 −2 tasks/jsmin-sourcemap.js
  5. +9,404 −0 test/test_files/jquery.js
  6. +1,200 −0 test/test_files/underscore.js
View
@@ -1 +1,2 @@
-/node_modules
+/node_modules
+/test/actual
View
@@ -18,7 +18,7 @@ grunt.loadNpmTasks('grunt-jsmin-sourcemap');
_(Coming soon)_
## Contributing
-In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt].
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via [grunt][grunt] and test via `npm test`.
## License
Copyright (c) 2012 Todd Wolfson
View
@@ -27,7 +27,7 @@
"node": ">=0.6"
},
"scripts": {
- "test": "grunt test"
+ "test": "grunt --base ./test/ --config ./test/grunt.js"
},
"dependencies": {
"grunt": "~0.3.12",
View
@@ -1,5 +1,33 @@
+var jsmin = require('jsmin-sourcemap');
module.exports = function (grunt) {
- grunt.registerTask('jsmin-sourcemap', 'Generate minified JavaScript and sourcemap from files', function() {
- grunt.log.write(grunt.helper('jsmin-sourcemap'));
+ grunt.registerMultiTask('jsmin-sourcemap', 'Generate minified JavaScript and sourcemap from files', function () {
+ // Grab the files to minify
+ var file = this.data,
+ srcFile = file.src,
+ srcFiles = grunt.file.expand(srcFile);
+
+ // Map each file into a JSMin input
+ var input = srcFiles.map(function (file) {
+ var code = grunt.file.read(file),
+ src = file;
+ return {'code': code, 'src': src};
+ });
+
+ // Minify the input
+ var destFile = file.dest,
+ retObj = jsmin({
+ 'input': input,
+ 'dest': destFile
+ });
+
+ // Grab the minified code
+ var code = retObj.code;
+
+ // Append a sourceMappingURL to the code
+ code = code + '\n//@ sourceMappingURL=' + destFile;
+
+ // Write out the code and map
+ grunt.file.write(destFile, code);
+ grunt.file.write(file.destMap, retObj.sourcemap);
});
};
Oops, something went wrong.

0 comments on commit 3546c6d

Please sign in to comment.