From d77c1924660a65fa99c4e12aaae91fa0b4b497bb Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 2 Dec 2016 10:34:06 -0600 Subject: [PATCH] babel min (#144) --- gulp/tasks/build.js | 27 +++++++++++++++++++++-- package.json | 4 ++++ src/shared/behaviors/sizeresponsible.html | 10 ++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js index 27eaca73..31b9d23d 100644 --- a/gulp/tasks/build.js +++ b/gulp/tasks/build.js @@ -9,6 +9,8 @@ var autoprefixer = require('autoprefixer'); var hogan = require('hogan.js'); var Vulcanize = require('vulcanize'); + var cheerio = require('cheerio'); + var babel = require('babel-core'); //stream/gulp related var merge = require('merge-stream'); @@ -107,6 +109,25 @@ }); } + function inlineBabel(opts) { + opts = opts || {}; + return through.obj(function (file, enc, cb) { + var fileContent = file.contents.toString("utf8"); + var ch = cheerio.load(fileContent, { + withStartIndices: true + }); + ch('script').each(function(index, el) { + var script = cheerio(this).text(); + var o = babel.transform(script, opts.babel || { + presets:['babili'] + }); + cheerio(this).text(o.code); + }); + file.contents = new Buffer(ch.html()); + cb(null, file); + }); + } + gulp.task('vulcanize', function() { var moduleGlob = j(C.BUILD,C.MODULE_MASK, C.MODULE_HTML); var excludes = glob.sync(moduleGlob); @@ -184,7 +205,8 @@ empty: true, spare: true })) - .pipe(plugins.inlinemin()) + .pipe(inlineBabel()) + .pipe(plugins.inlinemin({js:false})) .pipe(plugins.header('')) .pipe(C.dbg('vulcanize-modules')) .pipe(gulp.dest(C.DIST)); @@ -201,7 +223,8 @@ empty: true, spare: true })) - .pipe(plugins.inlinemin()) + .pipe(inlineBabel()) + .pipe(plugins.inlinemin({js:false})) .pipe(plugins.header('')) .pipe(C.dbg('vulcanize-lib')) .pipe(gulp.dest(C.DIST)); diff --git a/package.json b/package.json index 7a031be1..754abea2 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,10 @@ }, "devDependencies": { "autoprefixer": "^6.1.2", + "babel-core": "^6.0.2", + "babel-preset-babili": "0.0.9", + "babel-preset-es2015": "^6.18.0", + "cheerio": "^0.22.0", "connect": "^3.4.1", "del": "^2.0.2", "event-stream": "^3.3.2", diff --git a/src/shared/behaviors/sizeresponsible.html b/src/shared/behaviors/sizeresponsible.html index fbdd68c9..4e785513 100644 --- a/src/shared/behaviors/sizeresponsible.html +++ b/src/shared/behaviors/sizeresponsible.html @@ -4,7 +4,7 @@ This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt --> -