fix: use babili to minify ES6 sources.

This commit is contained in:
Luca Greco 2016-11-22 16:46:39 +01:00 committed by Luca Greco
parent 31d778c2cd
commit 9a38d923e9
2 changed files with 22 additions and 25 deletions

View File

@ -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 * 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/. */`; * 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) { module.exports = function(grunt) {
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON("package.json"), pkg: grunt.file.readJSON("package.json"),
@ -64,33 +66,25 @@ module.exports = function(grunt) {
}, },
}, },
"closure-compiler": { babel: {
dist: { minify: {
files: {
"dist/browser-polyfill.min.js": ["dist/browser-polyfill.js"],
},
options: { options: {
// Closure currently supports only whitespace and comment stripping babelrc: false,
// when both the input and output languages are ES6. comments: false,
compilation_level: "WHITESPACE_ONLY", presets: ["babili"],
language_in: "ECMASCRIPT6_STRICT", sourceMap: true,
language_out: "ECMASCRIPT6", },
output_wrapper: `${LICENSE}\n%output%`, files: {
"dist/browser-polyfill.min.js": "dist/browser-polyfill.js",
}, },
}, },
}, },
// This currently does not support ES6 classes. concat: {
uglify: { license: {
options: { src: "dist/browser-polyfill.min.js",
banner: LICENSE, dest: "dist/browser-polyfill.min.js",
compress: true, options: {footer: MINIFIED_FILE_FOOTER},
},
dist: {
files: {
"dist/browser-polyfill.min.js": ["dist/browser-polyfill.js"],
},
}, },
}, },
}); });
@ -99,7 +93,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-replace"); grunt.loadNpmTasks("grunt-replace");
grunt.loadNpmTasks("grunt-umd"); grunt.loadNpmTasks("grunt-umd");
grunt.loadNpmTasks("grunt-coveralls"); 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"]);
}; };

View File

@ -17,10 +17,12 @@
}, },
"homepage": "https://github.com/mozilla/webextension-polyfill", "homepage": "https://github.com/mozilla/webextension-polyfill",
"devDependencies": { "devDependencies": {
"babel-preset-babili": "0.0.10",
"chai": "^3.5.0", "chai": "^3.5.0",
"eslint": "3.9.1", "eslint": "3.9.1",
"google-closure-compiler": "^20160911.0.0",
"grunt": "^1.0.1", "grunt": "^1.0.1",
"grunt-babel": "^6.0.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-coveralls": "^1.0.1", "grunt-coveralls": "^1.0.1",
"grunt-replace": "*", "grunt-replace": "*",
"grunt-umd": "^2.4.0", "grunt-umd": "^2.4.0",