Last active
August 29, 2015 13:59
-
-
Save smuher/11002724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Grunt Initial Setup | |
1. $ npm install grunt-cli | |
2. $ cd /path/to/site | |
3. $ npm init | |
- Creates package.json file | |
5. $ npm install grunt --save-dev | |
- '--save-dev' keeps a reference to the dependencies in the package.json file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function (grunt) { | |
//Simple task without parameters | |
grunt.registerTask('affirm', function(){ | |
var affirmations = new Array( | |
"Way to go!", | |
"Your code rocks!", | |
"No bugs!"); | |
var index = Math.floor((Math.random()*3)); | |
grunt.log.writeln(affirmations[index]); | |
}); | |
//Simple with 1 parameter | |
grunt.registerTask('hello', function(name){ | |
grunt.log.writeln("Hello " + name); | |
}); | |
// Simple task with 2 parameters | |
grunt.registerTask('add', function(num1, num2){ | |
num1 = Number(num1); | |
num2 = Number(num2); | |
if(isNaN(num1)) | |
grunt.warn("Not num!"); | |
if(isNaN(num2)) | |
grunt.warn("Not num!"); | |
var sum = num1 + num2; | |
grunt.log.writeln("Sum is " + sum); | |
}); | |
//Set default tasks | |
grunt.registerTask('default', ['hello:Blend', 'affirm']); | |
//MULTITASKING | |
grunt.config.init({ | |
build: { | |
twojsfiles: { | |
src: ['files/a.txt', | |
'files/b.txt'], | |
dest: 'a-b.txt' | |
}, | |
alljsfiles: { | |
src: 'files/*.txt', | |
dest: 'all.txt' | |
} | |
} | |
}); | |
grunt.registerMultiTask('build', 'Compile javascript files.', function(){ | |
this.files.forEach(function(filegroup){ | |
var output = filegroup.src.map(function(filepath) { | |
return grunt.file.read(filepath); | |
}).join('\n'); | |
grunt.file.write(filegroup.dest, output); | |
}); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function (grunt) { | |
//PLUGINS / COMPILE SCSS | |
grunt.initConfig({ | |
// configurable paths | |
dir: { | |
app: 'path/to/site/files', | |
styles: 'path/to/stylesheets/directory', | |
js: 'path/to/javascripts/directory' | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-sass'); | |
grunt.config('sass', { | |
app: { | |
files: { | |
'<%= dir.styles %>/main.css': ['<%= dir.styles %>/main.scss'] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.config('watch', { | |
options: { | |
livereload: true | |
}, | |
styles: { | |
files: ['<%= dir.styles %>/{,**/}*.scss'], | |
tasks: ['sass'] | |
}, | |
files: [ | |
'<%= dir.app %>/templates/{,**/}/*.tpl', | |
'<%= dir.app %>/override/templates/{,**/}/*.tpl', | |
'<%= dir.app %>/*.css', | |
'<%= dir.app %>/stylesheets/main.scss', | |
'<%= dir.app %>/javascripts/{,*/}*.js', | |
'<%= dir.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}' | |
] | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment