Skip to content

Commit

Permalink
Move the buildsystem to rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Dec 7, 2020
1 parent 26d7a75 commit 3639cef
Show file tree
Hide file tree
Showing 15 changed files with 494 additions and 1,168 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
bower.json
composer.json
Gruntfile.js
rollup.config.js
78 changes: 3 additions & 75 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,96 +6,24 @@ var fs = require("fs"),
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
concat: {
options: {
banner: "/**\n" +
" * <%= pkg.name %>\n" +
" *\n" +
" * @copyright <%= grunt.template.today('yyyy') %> <%= pkg.author %>\n" +
" * @license <%= pkg.license %>\n" +
" * @version <%= pkg.version %>\n" +
" */\n"
},
dist: {
src: [
"<banner>",
"src/intro.js",
"src/filesize.js",
"src/outro.js"
],
dest: "lib/filesize.es6.js"
}
},
"babel": {
options: {
sourceMap: false,
presets: ["@babel/preset-env"]
},
dist: {
files: {
"lib/<%= pkg.name %>.js": "lib/<%= pkg.name %>.es6.js"
}
}
},

eslint: {
target: [
"Gruntfile.js",
"test/*.js",
"lib/<%= pkg.name %>.es6.js"
"src/*.js"
]
},
nodeunit: {
all: ["test/*.js"]
},
uglify: {
options: {
banner: "/*\n <%= grunt.template.today('yyyy') %> <%= pkg.author %>\n @version <%= pkg.version %>\n*/",
sourceMap: true,
sourceMapIncludeSources: true
},
target: {
files: {
"lib/filesize.min.js": ["lib/filesize.js"]
}
}
},
watch: {
js: {
files: "<%= concat.dist.src %>",
tasks: "build"
},
pkg: {
files: "package.json",
tasks: "build"
}
}
});

// tasks
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-nodeunit");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-eslint");
grunt.task.registerTask("babili", "Minifies ES2016+ code", function () {
const data = fs.readFileSync(path.join(__dirname, "lib", "filesize.es6.js"), "utf8"),
minified = require("babel-core").transform(data, {
sourceFileName: "filesize.es6.js",
sourceMaps: true,
presets: ["minify"]
}),
pkg = require(path.join(__dirname, "package.json")),
banner = "/*\n " + new Date().getFullYear() + " " + pkg.author + "\n @version " + pkg.version + "\n*/\n\"use strict\";";

fs.writeFileSync(path.join(__dirname, "lib", "filesize.es6.min.js"), banner + minified.code + "\n//# sourceMappingURL=filesize.es6.min.js.map", "utf8");
grunt.log.ok("1 file created.");
fs.writeFileSync(path.join(__dirname, "lib", "filesize.es6.min.js.map"), JSON.stringify(minified.map), "utf8");
grunt.log.ok("1 sourcemap created.");
});

// aliases
grunt.registerTask("test", ["eslint", "nodeunit"]);
grunt.registerTask("build", ["concat", "babel"]);
grunt.registerTask("default", ["build", "test", "babili", "uglify"]);
grunt.registerTask("default", ["test"]);
};
19 changes: 9 additions & 10 deletions lib/filesize.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* @license BSD-3-Clause
* @version 6.1.0
*/
(function (global) {
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.filesize = factory());
}(this, (function () { 'use strict';

const b = /^(b|B)$/,
symbol = {
iec: {
Expand Down Expand Up @@ -150,12 +155,6 @@
// Partial application for functional programming
filesize.partial = opt => arg => filesize(arg, opt);

// CommonJS, AMD, script tag
if (typeof exports !== "undefined") {
module.exports = filesize;
} else if (typeof define === "function" && define.amd !== void 0) {
define(() => filesize);
} else {
global.filesize = filesize;
}
}(typeof window !== "undefined" ? window : global));
return filesize;

})));
22 changes: 3 additions & 19 deletions lib/filesize.es6.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/filesize.es6.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 3639cef

Please sign in to comment.