binaryage/chromex

Best way to share code between components

LukeDefeo opened this issue · 2 comments

I have 3 components in my extension and 3 cljs builds:

  1. background page
  2. popup
  3. Custom settings page

What is the best way to to share fns between all of these. I have simply added a 4th cljs build and it works however this answer suggests there is a less bloaty way of doing it.

https://stackoverflow.com/questions/24227874/can-i-share-code-between-different-parts-of-chrome-extension

By adding another build it has to add the whole of clojurescript just for a few fns.

Well, you don't really need another cljs build. Simply put shared code on :source-paths of all your builds (e.g. src/shared) and require them in your ns forms. Google closure compiler will do the dead code elimination and include only used functions in your builds (assuming all works correctly).

Closing because this is not really chromex-related issue, but general clojurescript question. If you need further guidance please ask in #clojurescript channel on clojurian slack or elsewhere.