Skip to content

Instantly share code, notes, and snippets.

@steida
Last active March 14, 2016 17:27
Show Gist options
  • Save steida/afbc595a1e2f27e925d9 to your computer and use it in GitHub Desktop.
Save steida/afbc595a1e2f27e925d9 to your computer and use it in GitHub Desktop.
Add Closure as dependency in new Este.js
// package.json
{
"devDependencies": {
"google-closure-compiler": "^20150315.0.2",
"google-closure-library": "^20150315.0.0",
"gulp-closure-compiler": "^0.2.16"
}
}
// gulpfile.js
gulp.task('closure', function() {
return gulp.src([
'node_modules/google-closure-library/closure/**/*.js',
'src/lib/closure/src/**/*.js'
])
.pipe(closureCompiler({
compilerPath: 'node_modules/google-closure-compiler/compiler.jar',
fileName: 'index.js',
compilerFlags: {
'closure_entry_point': 'index',
'compilation_level': 'ADVANCED',
'define': [
'goog.DEBUG=false'
],
'externs': ['src/lib/closure/externs.js'],
'only_closure_dependencies': true,
'output_wrapper': '(function(){%output%}).call(window);',
'warning_level': 'VERBOSE'
}
}))
.pipe(gulp.dest('src/lib/closure'))
})
// src/lib/closure/src/index.js
/**
* @fileoverview Compile out Closure Library goodness.
*/
goog.provide('index')
goog.require('goog.dom.animationFrame')
exports['createAnimationFrameTask'] = function(mutate, opt_context) {
return goog.dom.animationFrame.createTask({
mutate: mutate
}, opt_context)
}
// src/lib/closure/externs.js
/**
* @type {Object}
*/
var module = {};
/**
* @type {*}
*/
var exports;
/**
* @type {Object.<string,*>}
*/
module.exports;
// src/client/components/app.jsx
import {createAnimationFrameTask} from '../../lib/closure'
// in componentDidMount method
this.animationFrameTask = createAnimationFrameTask(this.syncUI, this)
state.on('change', () => this.animationFrameTask());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment