From 9a38d923e9ddbf3bc4742dccc22afd53a9ad9683 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Tue, 22 Nov 2016 16:46:39 +0100 Subject: [PATCH] fix: use babili to minify ES6 sources. --- Gruntfile.js | 43 +++++++++++++++++++------------------------ package.json | 4 +++- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ba0b13b..86b9377 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,6 +8,8 @@ const LICENSE = `/* This Source Code Form is subject to the terms of the Mozilla * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */`; +const MINIFIED_FILE_FOOTER = `\n\n// <%= pkg.name %> v.<%= pkg.version %> (<%= pkg.homepage %>)\n\n${LICENSE}`; + module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), @@ -64,33 +66,25 @@ module.exports = function(grunt) { }, }, - "closure-compiler": { - dist: { - files: { - "dist/browser-polyfill.min.js": ["dist/browser-polyfill.js"], - }, + babel: { + minify: { options: { - // Closure currently supports only whitespace and comment stripping - // when both the input and output languages are ES6. - compilation_level: "WHITESPACE_ONLY", - language_in: "ECMASCRIPT6_STRICT", - language_out: "ECMASCRIPT6", - output_wrapper: `${LICENSE}\n%output%`, + babelrc: false, + comments: false, + presets: ["babili"], + sourceMap: true, + }, + files: { + "dist/browser-polyfill.min.js": "dist/browser-polyfill.js", }, }, }, - // This currently does not support ES6 classes. - uglify: { - options: { - banner: LICENSE, - compress: true, - }, - - dist: { - files: { - "dist/browser-polyfill.min.js": ["dist/browser-polyfill.js"], - }, + concat: { + license: { + src: "dist/browser-polyfill.min.js", + dest: "dist/browser-polyfill.min.js", + options: {footer: MINIFIED_FILE_FOOTER}, }, }, }); @@ -99,7 +93,8 @@ module.exports = function(grunt) { grunt.loadNpmTasks("grunt-replace"); grunt.loadNpmTasks("grunt-umd"); grunt.loadNpmTasks("grunt-coveralls"); - require("google-closure-compiler").grunt(grunt); + grunt.loadNpmTasks("grunt-contrib-concat"); + grunt.loadNpmTasks("grunt-babel"); - grunt.registerTask("default", ["eslint", "replace", "umd", "closure-compiler"]); + grunt.registerTask("default", ["eslint", "replace", "umd", "babel:minify", "concat:license"]); }; diff --git a/package.json b/package.json index 357b010..3abb325 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,12 @@ }, "homepage": "https://github.com/mozilla/webextension-polyfill", "devDependencies": { + "babel-preset-babili": "0.0.10", "chai": "^3.5.0", "eslint": "3.9.1", - "google-closure-compiler": "^20160911.0.0", "grunt": "^1.0.1", + "grunt-babel": "^6.0.0", + "grunt-contrib-concat": "^1.0.1", "grunt-coveralls": "^1.0.1", "grunt-replace": "*", "grunt-umd": "^2.4.0",