From 8cb2bfaea74bab87035bf7c6d130bb7dd38089dc Mon Sep 17 00:00:00 2001 From: Sean Tempesta Date: Wed, 30 Aug 2017 15:02:35 +0200 Subject: [PATCH] Removing automatic extern detection in favor of :infer-externs. Closes #12 and #16 --- README.md | 6 ++ project.clj | 2 +- resources/leiningen/new/expo/om/project.clj | 13 +-- .../leiningen/new/expo/reagent/project.clj | 83 ++++++++++--------- 4 files changed, 56 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index e664e23..b28052c 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,12 @@ lein prod-build ``` #### 3. Open XDE and [Publish](https://docs.expo.io/versions/latest/guides/publishing.html) +## Externs +Production builds use `advanced` closure compilation which sometimes cause problems with javascript interop ([details](https://github.com/cljsjs/packages/wiki/Creating-Externs)). In the past we ran a custom script to try and prepare a proper externs file, but I've found it to be [very](https://github.com/seantempesta/expo-cljs-template/issues/12) [problematic](https://github.com/seantempesta/expo-cljs-template/issues/16) and am now recommending the following: +* Try out the [:externs-inference](https://clojurescript.org/guides/externs#externs-inference) setting in the clojurescript compiler. It should be enabled by default in newer versions of this template. +* Use an interop package like [cljs-oops](https://github.com/binaryage/cljs-oops) for all `js` interop as dot references can get mangled `(.-property js-object)` +* Add your externs manually to `./js/externs.js` + ## Upgrading As this is only an initial template, you'll want to upgrade to newer versions of `expo`. Honestly, it's usually as easy as reading the latest [blog post](https://blog.expo.io/expo-sdk-v20-0-0-is-now-available-79f84232a9d1) for the new version diff --git a/project.clj b/project.clj index 67fa5b6..5e80af1 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject expo/lein-template "0.20.1" +(defproject expo/lein-template "0.20.2" :description "Expo template for Clojurescript." :url "https://github.com/seantempesta/expo-cljs-template" :license {:name "Eclipse Public License" diff --git a/resources/leiningen/new/expo/om/project.clj b/resources/leiningen/new/expo/om/project.clj index 39ad4cc..00c4a08 100644 --- a/resources/leiningen/new/expo/om/project.clj +++ b/resources/leiningen/new/expo/om/project.clj @@ -10,13 +10,13 @@ :plugins [[lein-cljsbuild "1.1.4"] [lein-figwheel "0.5.11"]] :clean-targets ["target/" "main.js"] - :aliases {"figwheel" ["run" "-m" "user" "--figwheel"] - "externs" ["do" "clean" - ["run" "-m" "externs"]] + :aliases {"figwheel" ["run" "-m" "user" "--figwheel"] + ; TODO: Remove custom extern inference as it's unreliable + ;"externs" ["do" "clean" + ; ["run" "-m" "externs"]] "rebuild-modules" ["run" "-m" "user" "--rebuild-modules"] - "prod-build" ^{:doc "Recompile code with prod profile."} - ["externs" - ["with-profile" "prod" "cljsbuild" "once" "main"]]} + "prod-build" ^{:doc "Recompile code with prod profile."} + ["with-profile" "prod" "cljsbuild" "once" "main"]} :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.11"] [com.cemerick/piggieback "0.2.1"]] :source-paths ["src" "env/dev"] @@ -35,6 +35,7 @@ :output-dir "target" :static-fns true :externs ["js/externs.js"] + :infer-externs true :parallel-build true :optimize-constants true :optimizations :advanced diff --git a/resources/leiningen/new/expo/reagent/project.clj b/resources/leiningen/new/expo/reagent/project.clj index cad1e46..ac4d3a6 100644 --- a/resources/leiningen/new/expo/reagent/project.clj +++ b/resources/leiningen/new/expo/reagent/project.clj @@ -1,42 +1,43 @@ (defproject {{name}} "0.1.0-SNAPSHOT" - :description "FIXME: write description" - :url "http://example.com/FIXME" - :license {:name "Eclipse Public License" - :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.9.0-alpha16"] - [org.clojure/clojurescript "1.9.854"] - [reagent "0.7.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server cljsjs/create-react-class]] - [re-frame "0.9.3"] - [react-native-externs "0.1.0"]] - :plugins [[lein-cljsbuild "1.1.4"] - [lein-figwheel "0.5.11"]] - :clean-targets ["target/" "main.js"] - :aliases {"figwheel" ["run" "-m" "user" "--figwheel"] - "externs" ["do" "clean" - ["run" "-m" "externs"]] - "rebuild-modules" ["run" "-m" "user" "--rebuild-modules"] - "prod-build" ^{:doc "Recompile code with prod profile."} - ["externs" - ["with-profile" "prod" "cljsbuild" "once" "main"]]} - :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.10"] - [com.cemerick/piggieback "0.2.1"]] - :source-paths ["src" "env/dev"] - :cljsbuild {:builds [{:id "main" - :source-paths ["src" "env/dev"] - :figwheel true - :compiler {:output-to "target/not-used.js" - :main "env.main" - :output-dir "target" - :optimizations :none}}]} - :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} - :prod {:cljsbuild {:builds [{:id "main" - :source-paths ["src" "env/prod"] - :compiler {:output-to "main.js" - :main "env.main" - :output-dir "target" - :static-fns true - :externs ["js/externs.js"] - :parallel-build true - :optimize-constants true - :optimizations :advanced - :closure-defines {"goog.DEBUG" false}}}]}}}) + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.9.0-alpha16"] + [org.clojure/clojurescript "1.9.854"] + [reagent "0.7.0" :exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server cljsjs/create-react-class]] + [re-frame "0.9.3"] + [react-native-externs "0.1.0"]] + :plugins [[lein-cljsbuild "1.1.4"] + [lein-figwheel "0.5.11"]] + :clean-targets ["target/" "main.js"] + :aliases {"figwheel" ["run" "-m" "user" "--figwheel"] + ; TODO: Remove custom extern inference as it's unreliable + ;"externs" ["do" "clean" + ; ["run" "-m" "externs"]] + "rebuild-modules" ["run" "-m" "user" "--rebuild-modules"] + "prod-build" ^{:doc "Recompile code with prod profile."} + ["with-profile" "prod" "cljsbuild" "once" "main"]} + :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.10"] + [com.cemerick/piggieback "0.2.1"]] + :source-paths ["src" "env/dev"] + :cljsbuild {:builds [{:id "main" + :source-paths ["src" "env/dev"] + :figwheel true + :compiler {:output-to "target/not-used.js" + :main "env.main" + :output-dir "target" + :optimizations :none}}]} + :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} + :prod {:cljsbuild {:builds [{:id "main" + :source-paths ["src" "env/prod"] + :compiler {:output-to "main.js" + :main "env.main" + :output-dir "target" + :static-fns true + :externs ["js/externs.js"] + :infer-externs true + :parallel-build true + :optimize-constants true + :optimizations :advanced + :closure-defines {"goog.DEBUG" false}}}]}}})