diff --git a/packages/babel-minify/src/index.js b/packages/babel-minify/src/index.js index fee17028d..8111632bc 100644 --- a/packages/babel-minify/src/index.js +++ b/packages/babel-minify/src/index.js @@ -5,26 +5,50 @@ module.exports = function babelMinify( input, // Minify options passed to minifyPreset // defaults are handled in preset - options = {}, + minifyOpts = {}, // overrides and other options { minified = true, inputSourceMap = null, sourceMaps = false, + comments = /^\**!|@preserve|@license|@cc_on/, // to override the default babelCore used babel = babelCore, // to override the default minify preset used - minifyPreset = babelPresetMinify + minifyPreset = babelPresetMinify, + + filename, + filenameRelative } = {} ) { return babel.transform(input, { + minified, babelrc: false, - presets: [[minifyPreset, options]], - comments: false, - inputSourceMap, + ast: false, + + presets: [[minifyPreset, minifyOpts]], + sourceMaps, - minified + inputSourceMap, + + shouldPrintComment(contents) { + return shouldPrintComment(contents, comments); + }, + + filename, + filenameRelative }); }; + +function shouldPrintComment(contents, predicate) { + switch (typeof predicate) { + case "function": + return predicate(contents); + case "object": + return predicate.test(contents); + default: + return !!predicate; + } +} diff --git a/packages/gulp-babel-minify/__tests__/__snapshots__/gulp-babili-test.js.snap b/packages/gulp-babel-minify/__tests__/__snapshots__/gulp-babel-minify-test.js.snap similarity index 100% rename from packages/gulp-babel-minify/__tests__/__snapshots__/gulp-babili-test.js.snap rename to packages/gulp-babel-minify/__tests__/__snapshots__/gulp-babel-minify-test.js.snap diff --git a/packages/gulp-babel-minify/__tests__/gulp-babili-test.js b/packages/gulp-babel-minify/__tests__/gulp-babel-minify-test.js similarity index 100% rename from packages/gulp-babel-minify/__tests__/gulp-babili-test.js rename to packages/gulp-babel-minify/__tests__/gulp-babel-minify-test.js diff --git a/packages/gulp-babel-minify/src/index.js b/packages/gulp-babel-minify/src/index.js index a6d6961d5..1acbc19da 100644 --- a/packages/gulp-babel-minify/src/index.js +++ b/packages/gulp-babel-minify/src/index.js @@ -15,7 +15,7 @@ function gulpBabelMinify( { babel = babelCore, minifyPreset = babelPresetMinify, - comments = /preserve|licen(s|c)e/ + comments = /^\*\*\!|@preserve|@license|@cc_on/ } = {} ) { return through2.obj(function(file, enc, callback) {