Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 2.21 KB

File metadata and controls

76 lines (53 loc) · 2.21 KB

martini-bundle

martini-bundle adds resource bundling and minification to Martini.

Build State

wercker status

Getting Started

Install all the packages (go 1.1 and greater is required):

go get github.com/fjdumont/martini-bundle/...

and

import "github.com/fjdumont/martini-bundle/scriptbundle"
import "github.com/fjdumont/martini-bundle/stylebundle"

Components

scriptbundle

martini-bundle/scriptbundle adds concatenation, scope wrapping and minification to your JavaScript files.

  • concatenation: simply concatenates all file contents
  • scope wrapping: wraps an IIFE/IFFY/SIAF around the concatenated scripts
  • minification: uses the Closure Compiler Service REST API to minify your scripts

Simply use scriptbundle.Default(files ...string) as a martini.Handler to register your script files as a bundle:

m := martini.Classic()
m.Get("/js/app.js", scriptbundle.Default(
  "public/js/jquery.js",
  "public/js/app-utils.js",
  "public/js/app.js",
))

Alternatively, plug your own scriptbundle.Options into scriptbundle.Bundle(opts *scriptbundle.Options, files ...string) to customize your optimizations:

type Options struct {
  Wrap   bool
  Minify bool
}

stylebundle

martini-bundle/stylebundle adds concatenation and minification to your Styleseets.

  • concatenation: simply concatenates all file contents
  • minification: uses the CSS Minifier REST API to minify your styles

Use stylebundle.Default(files ...string) as a martini.Handler to compile your styles into a bundle and use them:

m := martini.Classic()
m.Get("/css/app.css", stylebundle.Default(
  "public/js/vendor/bootstrap.css",
  "public/js/vendor/bootstrap-responsive.css",
  "public/js/app.css",
))

Alternatively, plug your own stylebundle.Options into stylebundle.Bundle(opts *stylebundle.Options, files ...string) to customize your optimizations:

type Options struct {
  Minify bool
}