On Github tylerjohnst / asset-talk
Created by Tyler Johnston / @tylerjohnst
I prefer the command line and since this is a Javascript meetup I'll be walking through Grunt. (It's also one of the few I've used)
Bower is a dependancy management tool for CSS and Javascript libraries. Bower has a similar API to NPM. By default will clone the git repo to $PROJECT_ROOT/bower_components. This allows you to easially keep and manage third party libraries without keeping them in your code repo.
bower install bootstrap --save-devAutomate your tasks away with grunt. Grunt is a task generator similar to Rake, Make, Cake, etc.
Grunt has plugins for every popular framework, tool, library, or latest test framework created a few minutes ago.
# Gruntfile.coffee module.exports = (grunt) -> grunt.initConfig pkg: grunt.file.readJSON("package.json")
A very large collection of Grunt packages are available on Github and NPM as grunt-contrib-*
npm install grunt-contrib-mylib --save-dev
# Gruntfile.coffee module.exports = (grunt) -> grunt.loadNpmTasks "grunt-contrib-mylib" grunt.initConfig mylib: taskname: options: []
# Gruntfile.coffee module.exports = (grunt) -> grunt.loadNpmTasks "grunt-contrib-concat" grunt.loadNpmTasks "grunt-contrib-uglify" grunt.initConfig pkg: grunt.file.readJSON("package.json") concat: javascripts: files: "tmp/application.concat.js": [ "vendor/javascripts/jquery-1.10.2.min.js", "vendor/javascripts/lodash.compat.js", "vendor/javascripts/backbone.js", "vendor/javascripts/chosen.jquery.js", "vendor/javascripts/bootstrap.js", "app/application.js", "app/**/*.js" ] uglify: compile: files: "public/application.js" : ['tmp/application.concat.js'] grunt.registerTask "compile:javascripts", ["concat:javascripts", "uglify:javascripts"]To compile you just run: grunt compile:javascripts
# Gruntfile.coffee module.exports = (grunt) -> grunt.loadNpmTasks "grunt-contrib-concat" grunt.initConfig pkg: grunt.file.readJSON("package.json") concat: stylesheets: files: "public/application.css": [ "vendor/stylesheets/bootstrap.css", "app/stylesheets/**/*.css" ] grunt.registerTask("compile:stylesheets", ["concat:stylesheets"])To compile you just run: grunt compile:javascripts
# Gruntfile.coffee module.exports = (grunt) -> grunt.loadNpmTasks "grunt-contrib-watch" grunt.initConfig pkg: grunt.file.readJSON("package.json") watch: stylesheets: files: ["app/stylesheets/**/*", "app/vendor/stylesheets/**/*"] tasks: ["compile:stylesheets"] javascripts: files: ["app/javascripts/**/*.coffee", "app/javascripts/**/*.html", "app/vendor/javascripts"] tasks: ["compile:javascripts"]Running grunt watch will set up the watcher process that will execute the tasks when a file changes on disk.
<link rel="stylesheet" type="text/css" href="/application.css"> <script src="/application.js"></script>
These examples are only the beginning of what you can do with grunt. Check out the gruntjs orgnanization on Github to see all the active projects they have going.
I'm currently building an application using this as it's own asset pipeline. It works great for getting started but there are issues.
Brocolli - Built for speed. Uses a similar API to Grunt. Handles things like keeping caches of compiled JS so compile time is significantly faster. Written in Javascript and uses Node.js. Still very new and considered alpha quality software.
Middleman - A Ruby alternative and my go-to for static site frontends. Essentially the Rails 3 asset pipeline for static sites. Works with any Ruby library built with Rails. Lots of out of the box support for this and can be very powerful with little to no configuration.
Questions? Comments?
@tylerjohnst