duct-framework / module.cljs

Duct module for developing and compiling ClojureScript
2 stars 6 forks source link

Add Service Worker support to module.cljs #8

Open Zaphodious opened 6 years ago

Zaphodious commented 6 years ago

Add support for service worker compilation. Clojurescript dependency bumped to 1.10 to allow for :target :webworker. Separate compiler opts map used for dev and production, with options conducive to service worker development and use. Of special note is :language-in :es6, :rewrite-polyfills true due to service workers requiring the use of js promises, :output-to (str path "/sw.js") due to service workers needing to be served from the same directory as the site they control, and :infer-externs true to assist with development as obscure closure errors are hard to debug when figwheel isn't a thing. (Externs inference is kept for deployment due to the negative impact being either compile-time-only when enabled, or potentially breaking when dev and prod have this set differently). Also of note is that this change is independent of figwheel, as the duct workflow refreshes the service worker file on (reset) (which can then be updated in whatever way required by the browser being used).

As a result of this pull request, adding service worker support to a project is as easy as creating a new cljs namespace and pointing module.cljs to it, like so- :duct.module/cljs {:sw-main project-name.sw}

Zaphodious commented 6 years ago

As an aside, this is so far the easiest way I've found to get figwheel to run alongside a service worker build. Usually it gripes with me until I beat it into submission or give up.

Zaphodious commented 6 years ago

Hello there! Was there a problem with this pull request? Should I change something?

weavejester commented 6 years ago

Hi, sorry for the late response! This managed to slip off my todo list. Can you adjust your PR so that it adheres to the new contributing guidelines that I intend to add to my repositories?