diff --git a/.gitignore b/.gitignore index c53038e..7784934 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,8 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +/.idea/ +*.idea +.idea +*.iml +.iml \ No newline at end of file diff --git a/project.clj b/project.clj index f6ea0f5..31395a0 100644 --- a/project.clj +++ b/project.clj @@ -1,10 +1,10 @@ -(defproject duct/module.cljs "0.3.2" +(defproject duct/module.cljs "0.4.0" :description "Duct module for developing and compiling ClojureScript" :url "https://github.com/duct-framework/module.cljs" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.9.0-RC2"] - [org.clojure/clojurescript "1.9.946"] + :dependencies [[org.clojure/clojure "1.9.0"] + [org.clojure/clojurescript "1.10.238"] [binaryage/devtools "0.9.7"] [duct/core "0.6.1"] [duct/compiler.cljs "0.2.0"] diff --git a/src/duct/module/cljs.clj b/src/duct/module/cljs.clj index 438b040..be41ab7 100644 --- a/src/duct/module/cljs.clj +++ b/src/duct/module/cljs.clj @@ -18,26 +18,58 @@ (defn- target-public-path [config options] (str core/target-path "/resources/" (project-dirs config options) "/public")) -(defn- compiler-config [path main] +(defn- compiler-config [path main sw-main] {:duct.compiler/cljs {:builds ^:displace - [{:source-paths ["src"] - :build-options - {:main main - :output-to (str path "/js/main.js") - :output-dir (str path "/js") - :asset-path "/js" - :closure-defines {'goog.DEBUG false} - :verbose true - :optimizations :advanced}}]}}) + [(when sw-main + {:id "sw" + :source-paths ["src"] + :build-options + {:main sw-main + :output-to (str path "/sw.js") + :output-dir (str path "/sw") + :asset-path "/sw" + :closure-defines {'goog.DEBUG false} + :verbose true + :infer-externs true + :language-in :es6 + :rewrite-polyfills true + :optimizations :advanced + :target :webworker}}) + {:source-paths ["src"] + :build-options + {:main main + :output-to (str path "/js/main.js") + :output-dir (str path "/js") + :asset-path "/js" + :closure-defines {'goog.DEBUG false} + :verbose true + :optimizations :advanced}}]}}) -(defn- figwheel-config [path main] +(defn- figwheel-config [path main sw-main] {:duct.server/figwheel {:css-dirs ^:displace ["resources" "dev/resources"] :builds ^:displace - [{:id "dev" + [(when sw-main + {:id "sw-dev" + :figwheel false + :source-paths ["dev/src" "src"] + :build-options + {:main sw-main + :output-to (str path "/sw.js") + :output-dir (str path "/sw") + :asset-path "/sw" + :closure-defines {'goog.DEBUG true} + :verbose false + :infer-externs true + :language-in :es6 + :rewrite-polyfills true + :preloads '[devtools.preload] + :optimizations :none + :target :webworker}}) + {:id "dev" :figwheel true - :source-paths ["dev/src" "src" ] + :source-paths ["dev/src" "src"] :build-options {:main main :output-to (str path "/js/main.js") @@ -51,7 +83,8 @@ (defmethod ig/init-key :duct.module/cljs [_ options] {:fn (fn [config] (let [path (target-public-path config options) + sw-main (:sw-main options) main (:main options)] (case (get-environment config options) - :production (core/merge-configs config (compiler-config path main)) - :development (core/merge-configs config (figwheel-config path main)))))}) + :production (core/merge-configs config (compiler-config path main sw-main)) + :development (core/merge-configs config (figwheel-config path main sw-main)))))}) diff --git a/test/duct/module/cljs_test.clj b/test/duct/module/cljs_test.clj index 05c9627..0776da1 100644 --- a/test/duct/module/cljs_test.clj +++ b/test/duct/module/cljs_test.clj @@ -7,6 +7,11 @@ (core/load-hierarchy) +(def service-worker-base-config + {:duct.core/project-ns 'foo + :duct.module/cljs {:main 'foo.client + :sw-main 'foo.sw}}) + (def base-config {:duct.core/project-ns 'foo :duct.module/cljs {:main 'foo.client}}) @@ -14,13 +19,27 @@ (defn- absolute-path [relative-path] (.getAbsolutePath (io/file relative-path))) -(deftest module-test - (testing "production config" - (is (= (core/prep base-config) - (merge base-config +(deftest service-worker-module-test + (testing "production config with service worker" + (is (= (core/prep service-worker-base-config) + (merge service-worker-base-config {:duct.compiler/cljs {:builds - [{:source-paths ["src"] + [{:id "sw" + :source-paths ["src"] + :build-options + {:main 'foo.sw + :output-to (absolute-path "target/resources/foo/public/sw.js") + :output-dir (absolute-path "target/resources/foo/public/sw") + :asset-path "/sw" + :closure-defines {'goog.DEBUG false} + :verbose true + :infer-externs true + :language-in :es6 + :rewrite-polyfills true + :optimizations :advanced + :target :webworker}} + {:source-paths ["src"] :build-options {:main 'foo.client :output-to (absolute-path "target/resources/foo/public/js/main.js") @@ -30,14 +49,30 @@ :verbose true :optimizations :advanced}}]}})))) - (testing "development config" - (let [config (assoc base-config ::core/environment :development)] + (testing "development config with service worker" + (let [config (assoc service-worker-base-config ::core/environment :development)] (is (= (core/prep config) (merge config {:duct.server/figwheel {:css-dirs ["resources" "dev/resources"] :builds - [{:id "dev" + [{:id "sw-dev" + :figwheel false + :source-paths ["dev/src" "src"] + :build-options + {:main 'foo.sw + :output-to (absolute-path "target/resources/foo/public/sw.js") + :output-dir (absolute-path "target/resources/foo/public/sw") + :asset-path "/sw" + :closure-defines {'goog.DEBUG true} + :verbose false + :infer-externs true + :language-in :es6 + :rewrite-polyfills true + :preloads '[devtools.preload] + :optimizations :none + :target :webworker}} + {:id "dev" :figwheel true :source-paths ["dev/src" "src"] :build-options @@ -49,3 +84,41 @@ :verbose false :preloads ['devtools.preload] :optimizations :none}}]}})))))) + +(deftest module-test + (testing "production config without service worker" + (is (= (core/prep base-config) + (merge base-config + {:duct.compiler/cljs + {:builds + [nil + {:source-paths ["src"] + :build-options + {:main 'foo.client + :output-to (absolute-path "target/resources/foo/public/js/main.js") + :output-dir (absolute-path "target/resources/foo/public/js") + :asset-path "/js" + :closure-defines {'goog.DEBUG false} + :verbose true + :optimizations :advanced}}]}})))) + + (testing "development config without service worker" + (let [config (assoc base-config ::core/environment :development)] + (is (= (core/prep config) + (merge config + {:duct.server/figwheel + {:css-dirs ["resources" "dev/resources"] + :builds + [nil + {:id "dev" + :figwheel true + :source-paths ["dev/src" "src"] + :build-options + {:main 'foo.client + :output-to (absolute-path "target/resources/foo/public/js/main.js") + :output-dir (absolute-path "target/resources/foo/public/js") + :asset-path "/js" + :closure-defines {'goog.DEBUG true} + :verbose false + :preloads ['devtools.preload] + :optimizations :none}}]}})))))) \ No newline at end of file