I have the following in my project.clj file
:clean-targets [:target-path
:compile-path "classes"
:output-paths ["build/js/output" "js/output" "output"]
"build/js/main.js.map"
]
.....
:output-to "build/js/main.js",
:output-dir "build/js/output"
:optimizations :simple,
:source-map "build/js/main.js.map",
:asset-path "js/out"
When trying to run lein clean the "build/js/output" file doesn't get deleted. Is the "output-dir" directory protected?
By default lein clean removes only target directory. You can customize which directories should be cleaned by setting :clean-targets in project.clj:
:clean-targets [:target-path "build/js/output"]
Related
I have a question regarding of the usage of profiles and environment variables. Is it possible to export variables with environ depending on the which profile is set? This is what I have tried (partial project.clj)
:env {:time-to-wait-for-response "72" ; in hours
:crm-address "https://app.onepagecrm.com/api/v3/"}
:profiles
{:uberjar {:omit-source true
:aot :all}
:uberwar {:omit-source true
:aot :all}
:prod {:ring {:open-browser? false
:stacktraces? false
:auto-reload? false}
{:env {:prod? true
:db-user "mailer"
:db-password "" }}
:dev {:env {:db-user "mailer"
:db-password ""}
:dependencies [[ring-mock "0.1.5"]
[ring/ring-devel "1.3.1"]
[midje "1.6.3"]]
:ring {:open-browser? false}
:plugins [[lein-midje "3.2.1"]]}})
However if I build the WAR file with lein ring uberwar(even with with-profile dev) and deploy it to Tomcat I will get db-user as nil (called with (env :db-user). However lein ring server correctly uses dev profile so it works. Is there something wrong I am doing? Or environ is not supposed to be used this way?
This reason it is not working as you expect is because you're only setting those variables when the profile is active. Once you have built a WAR file and deployed it, lein is no longer in the picture. You'll need to load these variables in a different way. If you want to stick with environ, the two options seem to be as Java system properties or environment variables.
I'm new to Clojure and I'm trying to setup a development environment where I can dynamically load my web project files using ring-server and cljsbuild
i have the following snippet in my project file
:ring {
:handler cjohansen-no.web/app
;;:auto-refresh true
;;:auto-reload? true
;;:reload-paths ["resources","src"]
;;:refresh-paths ["resources","src"]
}
:aliases {
"start-server" ["ring" "server-headless"]
"build-site" ["run" "-m" "cjohansen-no.web/export"]
"build-html" ["run" "-m" "cjohansen-no.web/export-pages"]
"build-js" ["cljsbuild" "auto" "dev"]
"build-web" ["do" ["build-site"] ["build-js"]]
"build-dev" ["pdo" ["build-web"] ["start-server"] ["auto" "build-html"]]
}
:source-paths ["src"]
:test-paths ["test/cjohansen_no" "test/cljs" "spec"]
:clean-targets [:target-path "./build/js/out"
:compile-path "classes"
:output-paths "./build/js/output"
"build/js/main.js.map"
]
:main cjohansen-no.web
:clean-non-project-classes true
:figwheel {
;;:server-port 3000
:css-dirs ["resources/public/css"]
:reload-clj-files {:clj true :cljc false}
:ring-handler cjohansen-no.web/app
:repl false
}
:cljsbuild {
:builds [
{
;; :notify-command ["growlnotify" "-m"]
:id "dev"
:source-paths ["src/cljs"]
:figwheel {
:websocket-host :js-client-host
:autoload false
:reload-dependents true
:debug true
}
:compiler {
:main scripts.core
:output-to "resources/public/js/main.js"
:output-dir "resources/public/js/out"
:optimizations :none
:source-map true
:source-map-timestamp true
:recompile-dependents false
:pretty-print true
:asset-path "js/out"
;;:notify-command ["bin/phantomjs" "bin/speclj.js" "resources/public/js/main.js"]
}
},
....
}
:profiles {
:dev {
:dependencies [
;;[figwheel "0.5.4-7"]
]
:plugins [
[lein-pdo "0.1.1"]
[lein-ring "0.9.7"]
[lein-cljsbuild "1.1.3"]
[lein-figwheel "0.5.4-7"]
]
}
I use this snippet to run my server
(def app (->
(stasis/serve-pages get-pages)
(optimus/wrap get-assets optimizations/all serve-live-assets)
;;(wrap-cljsbuild "/js/" cljsbuild)
wrap-content-type
;; wrap-reload
wrap-utf-8))
I'm loading my assets using Optimus
(defn get-assets []
(concat (assets/load-bundle "public" "styles.css" [#"css/.+\.css$"])
(assets/load-assets "public" [#"img/.*" "/questions.json"])
(assets/load-bundle "public" "main.js" [#"js/.+\.js"])
))
when I run lein with-profile dev pdf start-server, cljsbuild auto and bring up my website the js files and its dependants as compiled by the "dev" build takes FOREVER to complete loading. Why is the ring server so slow?
Should I be referencing the build files in this manner? should i bundle it into one file?
The profile used is for development purposes.
That is a pretty complex project.clj file if your just starting up and are new to clojure/clojurescript. It is possible that starting with just the bare lein figwheel template might be a good way to get a basic environment and then just add to it once you know you need additional bits. It could be that simply parsing your project file is slowing things down.
The basic figwheel template will set things up so that it all reloads when necessary - there really isn't much extra you need to worry about.
I have the following in my project.clj
:aliases {
"start-server" ["ring" "server-headless"]
"build-site" ["run" "-m" "cjohansen-no.web/export"]
"build-html" ["run" "-m" "cjohansen-no.web/export-pages"]
"build-prod" ["do" ["build-site"] ["cljsbuild" "once" "prod"]]
"build-js" ["cljsbuild" "auto" "dev"]
"watch-stuff" [ "do" ["start-server"] ["auto" "build-html"]]
"build-dev" ["do" ["build-site"] ["build-js"] ["watch-stuff"]]
}
:clean-targets [:target-path "./build/js/out"
:compile-path "classes"
:output-paths "./build/js/output"
"build/js/main.js.map"
]
:auto {"build-html" {:file-pattern #"\.(clj|hiccup)$" :paths ["src" "resources"]}}
:clean-non-project-classes true
:cljsbuild {
:builds [{
:id "dev"
:source-paths ["src/cljs"]
; :figwheel {
; :http-server-root "build"
; :css-dirs ["resources/public/css"]
; }
:compiler {
:main scripts.core,
:output-to "build/js/main.js",
:output-dir "build/js/out",
:optimizations :none,
:source-map true,
:source-map-timestamp true,
:recompile-dependents false
}
},
{
:id "prod"
:source-paths ["src/cljs"]
:compiler {
:main scripts.core,
:output-to "build/js/main.js",
:output-dir "build/js/output"
:optimizations :simple,
:source-map "build/js/main.js.map",
:asset-path "js/out"
:pretty-print true
}
}
]
}
I'm trying to automate my build by using aliases but don't seem to have it quite together...
running lein build-dev gets everything going except the "watch-stuff" which runs a [lien-auto] plugin and ring server but the it doesn't seem to function.
in the build output the last thing that happens is
Watching for changes before compiling ClojureScript...
Compiling "build/js/main.js" from ["src/cljs"]...
WARNING: test already refers to: cljs.core/test being replaced by: > scripts.core/test at line 5 src/cljs/scripts/core.cljs
Successfully compiled "build/js/main.js" in 4.54 seconds.
is there anything stopping this? how do I automate this in clojure?
Update
I've been moving stuff around and it seems that in some instances the specific task usually enters into its process....not sure if this causes the task executing afterwards to be suspended...does it?
e.g. if "ring" "server-headless" runs before "build-site" build-site does get run...
How do I then pass through the task and go on to the next one?
P.S. Gulp and Grunt was never this hard sigh
I'm making a Clojure/ClojureScript website that I deploy on Heroku. I'm using Leiningen for project management.
I want to write my stylesheets in LESS. I need the build process to compile the LESS files into CSS, then minify these CSS files; obviously, I do not want the generated CSS files to be under version control.
LESS files --lein-less--> CSS files --lein-asset-minifier--> minified CSS files
I have tried to implement this with the lein-less and lein-asset-minifier Leiningen plugins. My attempt consisted of declaring leiningen.less and minify-assets.plugin/hooks as hooks of the :uberjar task, in proper order (see code below). But running lein uberjar fails with the following error:
Uberjar aborting because jar failed: resources/public/css/site.css (No such file or directory)
So it appears the order of build steps is not enforced.
Is it possible to implement this multi-step build with these Leiningen plugins? If not, how are people doing it?
Code
Here is the relevant part of my project.clj :
(defproject sncf-cljs "0.1.0-SNAPSHOT"
;; ...
:min-lein-version "2.5.0"
:source-paths ["src/clj" "src/cljs"]
:dependencies [
;; ...
]
:plugins [
[lein-cljsbuild "1.0.4"]
[lein-environ "1.0.0"]
[lein-ring "0.9.1"]
[lein-asset-minifier "0.2.2"]
[lein-less "1.7.2"]]
:less {:source-paths ["src/less"]
:target-path "resources/public/css"}
:uberjar-name "sncf-cljs.jar"
:minify-assets {:assets
{"resources/public/css/site.min.css" "resources/public/css/site.css"}}
:cljsbuild {
;; ...
}
:profiles {
;; ...
:uberjar {:hooks [leiningen.less
leiningen.cljsbuild
minify-assets.plugin/hooks]
:env {:production true}
:aot :all
:omit-source true
:cljsbuild {:jar true
:builds {:app
{:source-paths ["env/prod/cljs"]
:compiler
{:optimizations :advanced
:pretty-print false}}}}}
:production {:ring {:open-browser? false
:stacktraces? false
:auto-reload? false}
:cljsbuild {:builds {:app {:compiler {:main "sncf-cljs.prod"}}}}
}})
I did some research because it is an interesting question. So I looked around, and could not find informations how to configure this. So I continued to search and I found a plugin for this task.
https://github.com/kumarshantanu/lein-cascade
The readme on the github page should be sufficient to solve this task.
I have a web application where i'm using Compojure on the server and Clojurescript on the client. I'm using the leing-cljsbuild plugin to automatically compile cljs files to js.
I'm able to generate the required client side files and load them in the browser when I set the optimizations to :whitespace or :simple, but when I set optimizations to none, the js files reference their dependencies using the local file-system path, which leads to the files not loading at all in the browser.
So, my question is how do I make the generated files use server urls instead of local file paths when they are generated by the clojurescript compiler.
Here's my project.clj file
(defproject my-proj-clj "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[org.clojure/tools.nrepl "0.2.3"]
[hiccup "1.0.3"]
[com.novemberain/monger "1.5.0"]
[org.clojure/clojurescript "0.0-2127"]
[jayq "2.5.0"]
]
:plugins [[lein-ring "0.8.8"]
[lein-cljsbuild "1.0.1"]
]
:ring {:handler my-proj-clj.handler/app
}
:cljsbuild { :builds
[{
:source-paths ["src/my-proj-clj"]
:compiler {
:output-dir "./resources/public/js"
:output-to "./resources/public/js/cljs-file.js"
:pretty-print true
:source-map "./resources/public/js/cljs-file.js.map"
:optimizations :none
}}]}
:profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]]}}
I believe the only valid optimization values are :whitespace, :simple, or :advanced. See line 96 at https://github.com/emezeske/lein-cljsbuild/blob/1.0.1/sample.project.clj.
Thus I would use :whitespace as the optimization level (at least to get something working).
Per your post, an optimization level of :whitespace works? Thus, perhaps you can elaborate.
What results are you expecting from an optimization level of ":none". How does your expected result differ from what an optimization level of :whitespace produces?
An optimization level of :none means cljsbuild is not generating js from your cljs source (it will generate a few goog.include statements but nothing else). Try using an interactive repl to help you prototype. Try running the following : lein trampoline cljsbuild repl-rhino
Hope that helps.
I have roughly same setup, optimizations set to :none, generated files use local paths. However, browser does load the scripts.
What I have is this in index.html:
<script src="js/development/goog/base.js" type="text/javascript"></script>
<script src="js/development/main.js" type="text/javascript" ></script>
<script type="text/javascript">goog.require("ixtlan.core");</script>
this in project.clj:
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src/cljs"]
:compiler {
:output-to "resources/public/js/development/main.js"
:output-dir "resources/public/js/development"
:optimizations :none
:source-map true}}
...
and routes contain:
(defroutes routes
(GET "/" [] (index))
(route/files "/" {:root "resources/public"}))
Hope, this helps.