Skip to content

Commit

Permalink
babel min (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlasky authored Dec 2, 2016
1 parent c53dd7c commit d77c192
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
27 changes: 25 additions & 2 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -184,7 +205,8 @@
empty: true,
spare: true
}))
.pipe(plugins.inlinemin())
.pipe(inlineBabel())
.pipe(plugins.inlinemin({js:false}))
.pipe(plugins.header('<!--\n' + fs.readFileSync('BANNER.txt','utf8') + ' -->'))
.pipe(C.dbg('vulcanize-modules'))
.pipe(gulp.dest(C.DIST));
Expand All @@ -201,7 +223,8 @@
empty: true,
spare: true
}))
.pipe(plugins.inlinemin())
.pipe(inlineBabel())
.pipe(plugins.inlinemin({js:false}))
.pipe(plugins.header('<!--\n' + fs.readFileSync('BANNER.txt','utf8') + ' -->'))
.pipe(C.dbg('vulcanize-lib'))
.pipe(gulp.dest(C.DIST));
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/shared/behaviors/sizeresponsible.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This code may only be used under the BSD style license found at http://mediamath.github.io/strand/LICENSE.txt
-->

<script type="text/javascript">
<script>
// adapted from https://github.com/sdecima/javascript-detect-element-resize/blob/3d9563692e169eb54f7c4fb96f4866aebc17cb4e/detect-element-resize.js
/**
* Detect Element Resize
Expand Down Expand Up @@ -33,7 +33,7 @@
return function(id){ return cancel(id); };
})();

function resetTriggers(element){
var resetTriggers = function resetTriggers(element){
if (!element.__resizeTriggers__) { return; } // diverges from 3d9563692e169eb54f7c4fb96f4866aebc17cb4e
var triggers = element.__resizeTriggers__,
expand = triggers.firstElementChild,
Expand All @@ -48,12 +48,12 @@
expand.scrollTop = expand.scrollHeight;
};

function checkTriggers(element){
var checkTriggers = function checkTriggers(element){
return element.offsetWidth != element.__resizeLast__.width ||
element.offsetHeight != element.__resizeLast__.height;
}
};

function scrollListener(e){
var scrollListener = function scrollListener(e){
var element = this;
resetTriggers(this);
if (this.__resizeRAF__) cancelFrame(this.__resizeRAF__);
Expand Down

0 comments on commit d77c192

Please sign in to comment.