├── README.org ├── build.boot └── src └── danielsz └── autoprefixer.clj /README.org: -------------------------------------------------------------------------------- 1 | * Boot-autoprefixer 2 | 3 | Boot task for [[https://github.com/postcss/autoprefixer][autoprefixer]]. 4 | 5 | #+BEGIN_QUOTE 6 | Autoprefixer utilizes the most recent data from Can I Use to add only necessary vendor prefixes. 7 | #+END_QUOTE 8 | 9 | ** Requirements 10 | 11 | Make sure postcss-cli and autoprefixer are installed on your system. 12 | #+BEGIN_SRC clojure 13 | npm install --global postcss-cli autoprefixer 14 | #+END_SRC 15 | 16 | ** Installation 17 | 18 | [[https://clojars.org/danielsz/boot-autoprefixer][https://img.shields.io/clojars/v/danielsz/boot-autoprefixer.svg]] 19 | 20 | 21 | ** Usage 22 | 23 | In *build.boot*, import the *autoprefixer* task: 24 | 25 | #+BEGIN_SRC clojure 26 | (set-env! :dependencies '[[danielsz/boot-autoprefixer "x.x.x"]]) ; latest release is indicated above 27 | (require '[danielsz.autoprefixer :refer [autoprefixer]]) 28 | #+END_SRC 29 | 30 | The autoprefixer task takes a vector of filenames, the CSS files you want to post-process with autoprefixer. 31 | 32 | #+BEGIN_SRC clojure 33 | (task-options! autoprefixer {:files ["style-1.css" "style-2.css"]}) 34 | #+END_SRC 35 | 36 | Autoprefixer uses [[https://github.com/ai/browserslist][Browserslist]], so you can specify the browsers you 37 | want to target in your project by queries like =last 2 versions= or => 5%= 38 | 39 | #+BEGIN_SRC clojure 40 | (task-options! autoprefixer {:files ["style-1.css" "style-2.css"] 41 | :browsers "last 2 versions"}) 42 | #+END_SRC 43 | 44 | You can now compose *autoprefixer* in your boot pipeline like any other task. 45 | 46 | An alternate way of going about this is to forgo *task-options!* and instead use keyword arguments. 47 | 48 | #+BEGIN_SRC clojure 49 | (comp 50 | (cljs :source-map true) 51 | (autoprefixer :files ["style-1.css" "style-2.css"] 52 | :browsers "last 2 versions")) 53 | #+END_SRC 54 | -------------------------------------------------------------------------------- /build.boot: -------------------------------------------------------------------------------- 1 | (set-env! 2 | :source-paths #{"src"} 3 | :resource-paths #{"src"}) 4 | 5 | (task-options! 6 | push {:repo-map {:url "https://clojars.org/repo/"}} 7 | pom {:project 'danielsz/boot-autoprefixer 8 | :version "0.1.0" 9 | :scm {:name "git" 10 | :url "https://github.com/danielsz/boot-autoprefixer"}}) 11 | 12 | (deftask build 13 | [] 14 | (comp (pom) (jar) (install))) 15 | 16 | (deftask push-release 17 | [] 18 | (comp 19 | (build) 20 | (push))) 21 | -------------------------------------------------------------------------------- /src/danielsz/autoprefixer.clj: -------------------------------------------------------------------------------- 1 | (ns danielsz.autoprefixer 2 | {:boot/export-tasks true} 3 | (:require 4 | [clojure.java.io :as io] 5 | [boot.pod :as pod] 6 | [boot.core :as core] 7 | [boot.util :as util] 8 | [boot.tmpdir :as tmpd])) 9 | 10 | (defn- find-css-files [fs files] 11 | (->> fs 12 | core/input-files 13 | (core/by-name files) 14 | (map (juxt core/tmp-path core/tmp-file identity)))) 15 | 16 | (core/deftask autoprefixer 17 | [p exec-path PATH str "PostCSS executable path (defaults to \"postcss\" if omitted)." 18 | f files FILES [str] "A vector of filenames to process with autoprefixer." 19 | b browsers BROWSERS str "A string describing browsers autoprefixer will target. 20 | Eg: \"last 1 version, > 5%\". 21 | More details at https://github.com/ai/browserslist"] 22 | (let [tmp-dir (core/tmp-dir!)] 23 | (core/with-pre-wrap fileset 24 | (doseq [[in-path in-file file] (find-css-files fileset files)] 25 | (boot.util/info "Autoprefixing %s\n" (:path file)) 26 | (let [out-file (doto (io/file tmp-dir in-path) io/make-parents) 27 | postcss (or exec-path "postcss") 28 | args (if browsers ["--autoprefixer.browsers" browsers] []) 29 | args (into args ["--" (.getPath in-file)])] 30 | (apply util/dosh postcss "--use" "autoprefixer" 31 | "-o" (.getPath out-file) 32 | args))) 33 | (-> fileset 34 | (core/add-resource tmp-dir) 35 | core/commit!)))) 36 | --------------------------------------------------------------------------------