I have many js es6 modules compiled by Closure Compiler (Advanced level) in a single library file.
I failed to export some symbols using /** @export */
or using goog.exportSymbol('whatever', whatever)
to uncompiled javascript in HTML pages .
How to do it?
Remarque: If I replace the es6 import
/export
by goog.require
/goog.provide
in all modules, it works and I can successfully use these symbols in HTML pages.
After further investigations, I found the solution.
Although loaded in the browser without any error in the console (except
undefined whatever
of course), my library was not executed. I simply moved the closure library ahead of the file stack to be compiled and my library was then properly executed by the browser with my symbols properly exported.The 3 ways to export symbols are working in compiled es6 modules:
/** @export */ whatever
,goog.exportSymbol('whatever', whatever)
,window['whatever'] = whatever
. The first 2 being a handy way for the third one.Fort more details see No exported symbols with es6 modules library compiled by Closure Compiler