Fork me on GitHub
#cljsjs
<
2016-04-28
>
leontalbot13:04:14

Hello! What do I do when js lib is only available minified?

leontalbot13:04:34

Would this be fine?

leontalbot13:04:52

(deftask package []
  (comp
   (download :url ""
             :name     "v2.js"
             :checksum "781618FEB2DA41191A8AB37D3EF5B674"
             :unzip false)
   (sift :move {#"v2.js" "cljsjs/stripe/development/stripe.inc.js"})
   (minify :in  "cljsjs/stripe/development/stripe.inc.js"
           :out "cljsjs/stripe/production/stripe.min.inc.js")
   ...))

leontalbot13:04:16

copy min source to development

leontalbot13:04:27

minify again for production

leontalbot13:04:38

when I boot prod a hoplon template (advanced compilation), it compiles fine.

juhoteperi14:04:55

@leontalbot: Isn't stripe already packaged?

leontalbot14:04:15

nope. task not completed

leontalbot14:04:24

(deftask package []
  (comp
    (pom)
    (jar)))

juhoteperi14:04:47

So? It doesn't need to do anything else. It is just for the extern.

leontalbot14:04:07

When I try I get

ERROR: No such namespace: cljsjs.stripe, could not locate cljsjs/stripe.cljs, cljsjs/stripe.cljc, or Closure namespace "cljsjs.stripe" in file /Users/leontalbot/.boot/cache/tmp/Users/leontalbot/Dropbox/Sites/hoplon-stripe/1d8/62mkia/hoplon/app_pages/_index_DOT_html.cljs at file hoplon/app_pages/_index_DOT_html.cljs

juhoteperi14:04:34

you don't need such require, the extern is used always

juhoteperi14:04:44

"The jar only provides an extern file required for advanced compilation. The Stripe js API will still need to be provided through some other mechanism."

juhoteperi14:04:04

Stripe.js file can't be packaged in the jar because it must/should be loaded directly from stripe server.

juhoteperi14:04:16

> Note: Stripe.js should be loaded directly from https://js.stripe.com/v2/. https://stripe.com/docs/stripe.js

juhoteperi14:04:50

This is because the library is not versioned, they update the code anytime and you might be vulnerable if you are using old version from the package.

leontalbot14:04:35

Not sure what "The Stripe js API will still need to be provided through some other mechanism." means

juhoteperi14:04:55

you shuld add <script type="text/javascript" src="https://js.stripe.com/v2/"></script> to your html

leontalbot14:04:36

thanks a lot!

juhoteperi14:04:52

This was discussed just few days ago, I'll write a wiki page about this

leontalbot14:04:35

one thing though

leontalbot14:04:12

the extern.js file is way shorter then when I use https://github.com/jmmk/javascript-externs-generator

juhoteperi14:04:12

It is written by hand. I don't know if it complete, but generator often includes unncesessary properties and methods.

juhoteperi14:04:13

E.g. methods prefixed with underscore are "private" and should not be called by application using the lib, thus they are not needed on the extern.

leontalbot14:04:38

good to know

leontalbot14:04:59

The tool I used is tagged "recommended" in the wiki. Not sure if the other one would be less verbose

juhoteperi14:04:23

The externs shoud be fine even if they include unncessary stuff. It might cause minor size increase in optimized output file, but the effect is probably minimal.