Skip to content

Instantly share code, notes, and snippets.

@mbixby
Last active December 19, 2015 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbixby/5952914 to your computer and use it in GitHub Desktop.
Save mbixby/5952914 to your computer and use it in GitHub Desktop.
Gruntfile
"use strict"
module.exports = (grunt) ->
grunt = (require 'grunt-utilities') grunt
# Note that for performance reasons we're only matching one level
# down: 'test/spec/{,*/}*.js'. If you want to match all subfolders,
# use 'test/spec/**/*.js'
grunt.initConfig
yeoman:
app: "app"
dist: "dist"
watch:
emberTemplates:
files: "<%= yeoman.app %>/templates/**/*.hbs"
tasks: ["emberTemplates", "livereload"]
coffee:
files: ["<%= yeoman.app %>/scripts/**/*.coffee"]
tasks: ["coffee:dist"]
coffeeTest:
files: ["test/spec/{,*/}*.coffee"]
tasks: ["coffee:test"]
compass:
files: ["<%= yeoman.app %>/styles/{,*/}*.{scss,sass}"]
tasks: ["compass:server"]
neuter:
files: [".tmp/scripts/**/*.js"]
tasks: ["neuter:app", "neuter:components", "livereload"]
livereload:
files: ["<%= yeoman.app %>/*.html", "{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css", "<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}"]
tasks: ["livereload"]
bower:
install:
options:
install: false
targetDir: '.tmp'
cleanup: no
layout: (type, component) ->
(require 'path').join 'components', component
connect:
options:
port: 9000
# Change this to '0.0.0.0' to access the server from outside
hostname: "localhost"
livereload:
options:
middleware: grunt.middleware (connect) ->
[connect.livereloadFolders(), ".tmp", "app"]
test:
options:
middleware: grunt.middleware (connect) ->
[".tmp", "test"]
dist:
options:
middleware: grunt.middleware (connect) ->
["dist"]
open:
server:
path: "http://localhost:<%= connect.options.port %>"
clean:
dist:
files: [
dot: true
src: [".tmp", "<%= yeoman.dist %>/*", "!<%= yeoman.dist %>/.git*"]
]
server: ".tmp"
jshint:
options:
jshintrc: ".jshintrc"
all: ["Gruntfile.js", "<%= yeoman.app %>/scripts/**/*.js", "!<%= yeoman.app %>/scripts/vendor/*", "test/spec/**/*.js"]
mocha:
all:
options:
run: true
urls: ["http://localhost:<%= connect.options.port %>/index.html"]
coffee:
dist:
files: [
expand: true
cwd: "<%= yeoman.app %>/scripts"
src: "**/*.coffee"
dest: ".tmp/scripts"
ext: ".js"
]
test:
files: [
expand: true
cwd: "test/spec"
src: "**/*.coffee"
dest: ".tmp/spec"
ext: ".js"
]
compass:
options:
sassDir: "<%= yeoman.app %>/styles"
cssDir: ".tmp/styles"
generatedImagesDir: ".tmp/images/generated"
imagesDir: "<%= yeoman.app %>/images"
javascriptsDir: "<%= yeoman.app %>/scripts"
fontsDir: "<%= yeoman.app %>/styles/fonts"
importPath: ["components"]
httpImagesPath: "/images"
httpGeneratedImagesPath: "/images/generated"
httpFontsPath: "/styles/fonts"
relativeAssets: false
dist: {}
server:
options:
debugInfo: true
rev:
dist:
files:
src: ["<%= yeoman.dist %>/scripts/**/*.js", "<%= yeoman.dist %>/styles/{,*/}*.css", "<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp}", "<%= yeoman.dist %>/styles/fonts/*"]
useminPrepare:
html: "<%= yeoman.app %>/index.html"
options:
dest: "<%= yeoman.dist %>"
usemin:
html: ["<%= yeoman.dist %>/{,*/}*.html"]
css: ["<%= yeoman.dist %>/styles/{,*/}*.css"]
options:
dirs: ["<%= yeoman.dist %>"]
imagemin:
dist:
files: [
expand: true
cwd: "<%= yeoman.app %>/images"
src: "{,*/}*.{png,jpg,jpeg}"
dest: "<%= yeoman.dist %>/images"
]
svgmin:
dist:
files: [
expand: true
cwd: "<%= yeoman.app %>/images"
src: "{,*/}*.svg"
dest: "<%= yeoman.dist %>/images"
]
cssmin:
dist:
files:
"<%= yeoman.dist %>/styles/main.css": [".tmp/styles/{,*/}*.css", "<%= yeoman.app %>/styles/{,*/}*.css"]
htmlmin:
dist:
files: [
expand: true
cwd: "<%= yeoman.app %>"
src: "*.html"
dest: "<%= yeoman.dist %>"
]
# Put files not handled in other tasks here
copy:
dist:
files: [
expand: true
dot: true
cwd: "<%= yeoman.app %>"
dest: "<%= yeoman.dist %>"
src: ["*.{ico,txt}", ".htaccess", "images/{,*/}*.{webp,gif}", "styles/fonts/*"]
]
concurrent:
server: ["emberTemplates", "coffee:dist", "compass:server"]
test: ["coffee", "compass"]
dist: ["emberTemplates", "coffee", "compass:dist", "imagemin", "svgmin", "htmlmin"]
emberTemplates:
options:
templateName: (sourceFile) ->
appPath = grunt.config 'yeoman.app'
templatePath = appPath + '/templates/'
sourceFile.replace templatePath, ''
dist:
files:
".tmp/scripts/compiled-templates.js": "<%= yeoman.app %>/templates/{,*/}*.hbs"
neuter:
options:
# In neuter:app, files are wrapped with the coffee task, no need
# to to it twice.
# In neuter:components, wrapping is left up to individual components
# since some components do not export their API to window
# or via AMD/CommonJS (e.g. Handlebars)
template: "{%= src %}"
loadPaths: ['.tmp/scripts', '.tmp/components', '.tmp']
filepathTransform: require 'neuter-grunt-resolve-path'
app:
src: [".tmp/scripts/app.js"]
dest: ".tmp/scripts/combined-scripts.js"
components:
src: [".tmp/scripts/components.js"]
dest: ".tmp/scripts/combined-components.js"
# Tasks
grunt.renameTask "regarde", "watch"
grunt.registerTask "server", (target) ->
grunt.task.run if target is "dist"
["build", "open", "connect:dist:keepalive"]
else
["clean:server", "bower", "concurrent:server", "neuter:app", "neuter:components", "livereload-start", "connect:livereload", "open", "watch"]
grunt.registerTask "test", ["clean:server", "bower", "concurrent:test", "neuter:app", "neuter:components", "connect:test", "mocha"]
grunt.registerTask "build", ["clean:dist", "useminPrepare", "bower", "concurrent:dist", "neuter:app", "neuter:components", "concat", "cssmin", "uglify", "copy", "rev", "usemin"]
grunt.registerTask "default", ["jshint", "build"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment