Skip to content

Commit 2edf1a3

Browse files
committed
Adding babili task to minify the es6 file, fixes #86
1 parent 77db546 commit 2edf1a3

9 files changed

+50
-17
lines changed

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/node_modules/
22
/lib/filesize.min.js
33
/lib/filesize.min.js.map
4+
/lib/filesize.es6.min.js
5+
/lib/filesize.es6.min.js.map
46
/src/
57
/test/
68
.idea
79
.eslintrc
810
.travis.yml
911
Gruntfile.js
12+
bower.json
13+
composer.json

Gruntfile.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"use strict";
2+
3+
var fs = require("fs"),
4+
path = require("path");
5+
16
module.exports = function(grunt) {
27
grunt.initConfig({
38
pkg : grunt.file.readJSON("package.json"),
@@ -40,10 +45,7 @@ module.exports = function(grunt) {
4045
},
4146
uglify: {
4247
options: {
43-
banner : "/*\n" +
44-
" <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
45-
" @version <%= pkg.version %>\n" +
46-
" */",
48+
banner: "/*\n<%= grunt.template.today('yyyy') %> <%= pkg.author %>\n @version <%= pkg.version %>\n*/",
4749
sourceMap: true,
4850
sourceMapIncludeSources: true
4951
},
@@ -72,9 +74,20 @@ module.exports = function(grunt) {
7274
grunt.loadNpmTasks("grunt-contrib-uglify");
7375
grunt.loadNpmTasks("grunt-babel");
7476
grunt.loadNpmTasks("grunt-eslint");
77+
grunt.task.registerTask("babili", "Minifies ES2016+ code", function () {
78+
var data = fs.readFileSync(path.join(__dirname, "lib", "filesize.es6.js"), "utf8"),
79+
minified = require("babel-core").transform(data, {sourceFileName: "filesize.es6.js", sourceMaps: true, presets: ["babili"]}),
80+
pkg = require(path.join(__dirname, "package.json")),
81+
banner = "/*\n " + new Date().getFullYear() + " " + pkg.author + "\n @version " + pkg.version + "\n*/\n\"use strict\";";
82+
83+
fs.writeFileSync(path.join(__dirname, "lib", "filesize.es6.min.js"), banner + minified.code + "\n//# sourceMappingURL=filesize.es6.min.js.map", "utf8");
84+
grunt.log.ok("Created minified es6 file");
85+
fs.writeFileSync(path.join(__dirname, "lib", "filesize.es6.min.js.map"), JSON.stringify(minified.map), "utf8");
86+
grunt.log.ok("Created minified es6 source map");
87+
});
7588

7689
// aliases
7790
grunt.registerTask("test", ["eslint", "nodeunit"]);
7891
grunt.registerTask("build", ["concat", "babel"]);
79-
grunt.registerTask("default", ["build", "test", "uglify"]);
92+
grunt.registerTask("default", ["build", "test", "babili", "uglify"]);
8093
};

lib/filesize.es6.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @copyright 2017 Jason Mulligan <[email protected]>
55
* @license BSD-3-Clause
6-
* @version 3.5.6
6+
* @version 3.5.7
77
*/
88
(function (global) {
99
const b = /^(b|B)$/,

lib/filesize.es6.min.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.es6.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filesize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* @copyright 2017 Jason Mulligan <[email protected]>
77
* @license BSD-3-Clause
8-
* @version 3.5.6
8+
* @version 3.5.7
99
*/
1010
(function (global) {
1111
var b = /^(b|B)$/,

lib/filesize.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)