Giter Club home page Giter Club logo

asset-minifier's Introduction

asset-minifier

Continuous Integration status

A Clojure library to minify HTML, CSS and Js resources, for a Leiningen plugin see lein-asset-minifier.

The latest version requires ClojureScript 1.9+. If you're on an older version of ClojureScript, then use version 0.2.0 instead.

Usage

Clojars Project

The minifier provides three functions called minify-html, minify-css and minify-js, all functions accept a source path followed by the output target and an optional parameter map. The source can be a filename, a directory, or a sequence of directories and or filenames.

(ns my.ns
  (:require [asset-minifier.core :refer [minify-html minify-css minfy-js minify]]))

The minify-html function allows specifying config for htmlcompressor. Please refer too clj-html-compressor.

; minify html files from folder /html into /minified
(minify-html "html" "minified")

The minify-css function allows specifying :linebreak to force line breaks after a certain number of chracters in the minified CSS.

;minify the site.css into site.min.css
(minify-css "site.css" "site.min.css")

;minify the site.css file and any files found under dev/resources/css
(minify-css ["site.css" "dev/resources/css"] "site.min.css")

(minify-css "site.css" "site.min.css" {:linebreak 80})

;minify all css resources into site.min.css
(minify-css "dev/resources/css" "resources/public/css/site.min.css")

The function returns a map containing :original-size, :compressed-size, and :gzipped-size keys indicating the size of the assets before and after compression.

The minify-js function allows specifying the level of optimizations, which can be :none, :simple, :whitespace or :advanced and defaults to simple optimizations.

The :externs key can be used to specify the externs file to be used with the advanced optimisations to prevent munging of external functions.

;minify site.js into site.min.js
(minify-js "site.js" "site.min.js")

;minify files found under dev/resources/js and dev/resources/vendor into site.min.js
(minify-js ["dev/resources/js" "dev/resources/vendor"] "site.min.js")

;minify site.js into site.min.js with advanced optimizations and jquery externs
(minify-js "site.js" "site.min.js" {:optimization :advanced
                                    :externs ["jquery.min.js"]})

;minify all Js resources into site.min.js
(minify-js "dev/resources/js" "resources/public/js/site.min.js")

The function returns a map containing :original-size, :compressed-size, and :gzipped-size keys indicating the size of the assets before and after compression. In addition the map may contain :warnings and :errors keys to indicate any warnings or errors that were issued during compilation.

Minify

The minify function can be used intead of functions describet below. It tales vector based config as argument. See example:

(minify [[:html {:source "dev/resource/html" :target "dev/minified/html"}]
         [:css {:source "dev/resources/css" :target "dev/minified/css/styles.min.css"}]
         [:js {:source ["dev/res/js1", "dev/res/js2"] :target "dev/minified/js/script.min.js"}]])

License

Copyright © 2017 Yogthos

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

asset-minifier's People

Contributors

yogthos avatar alehatsman avatar stephanos avatar rredpoppy avatar mavbozo avatar blak3mill3r avatar

Watchers

Nick Kabrich avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.