Search code examples
google-closure-compilerclojurescriptpolyfills

ClojureScript include polyfill


I want to include a polyfill in my ClojureScript application (specifically , an EventSource polyfill).

I would like to add it like so in my leiningen profile :

:foreign-libs [{:file "https://github.com/Yaffle/EventSource/blob/master/eventsource.min.js"
                :provides ["what.namespace.should.i.put.here"]}]

However this polyfill doesn't provide any namespace (it is a polyfill, not a library). Is it alright to leave the namespace empty ? Will it still include the polyfill ?


Solution

  • For the polyfill to be included in the build, the foreign-libs declaration should provide a namespace and the ns of at least one of your modules should :require the same namespace.

    Under simple optimization, you may take a look at the generated :output-to js file to verify the file has been properly included, likely early in the output unless the foreign-libs declaration specify namespace dependencies.