google / incremental-dom

An in-place DOM diffing library
http://google.github.io/incremental-dom/
Apache License 2.0
3.54k stars 178 forks source link

Closure Compiler compilation question #197

Open romanoff opened 8 years ago

romanoff commented 8 years ago

Hello. I wanted to write application with incremental dom and then compile it using Closure Compiler in advanced mode. Ideally I would not load incremental dom as extern, but as a package (this way theoretically I would get greater minification and if certain features were not used by me, they would be stripped down). Is it possible? Has anybody tried it? Example would be greatly appreicated

sparhami commented 8 years ago

I believe Closure Compiler can consume ES6 sources, though I haven't tried it yet myself.

If you aren't building with ES6, there is a build target to compile Incremental DOM to a goog.module (gulp js-closure). You can use this from other goog.modules as follows:

goog.module('my.module');

var IncrementalDom = goog.require('incrementaldom');

or from a traditional goog.provide'd file:

goog.provide('my.namespace');

goog.scope(function() {
  var IncrementalDom = goog.module.get('incrementaldom');
});

There is a problem with some parens needed for type-casts being dropped by Babel, but it works otherwise.

Dominator008 commented 8 years ago

Seems like the library itself can be compiled using Closure Compiler with a little effort. I'm experimenting with this in https://github.com/google/incremental-dom/pull/227.