Created
May 10, 2017 14:10
-
-
Save OrderAndCh4oS/c18a2113191e014b6a990c81c5e8f747 to your computer and use it in GitHub Desktop.
Grunt Setup for SASS and JS
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
module.exports = function (grunt) { | |
// This banner gets inserted at the top of the generated files, such a minified CSS | |
var bannerContent = '/*!\n' + | |
' * <%= pkg.name %>\n' + | |
' * Version: <%= pkg.version %>\n' + | |
' * Build date: <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>\n' + | |
' */\n\n'; | |
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks); | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
jshint: { | |
files: ['_js/main.js'], | |
options: { | |
forin: true, | |
noarg: true, | |
noempty: true, | |
eqeqeq: true, | |
bitwise: true, | |
undef: true, | |
unused: false, | |
curly: true, | |
browser: true, | |
devel: true, // Checks for console and alert if false | |
jquery: true, | |
maxerr: 25 | |
} | |
}, | |
concat: { | |
options: { | |
banner: bannerContent | |
}, | |
javascript: { | |
src: [ | |
'_js/vendor/jquery.repeatable.js', | |
'_js/plugins.js', | |
'_js/main.js', | |
'_js/validation.js' | |
], | |
dest: 'web/assets/js/all.js' | |
} | |
}, | |
uglify: { | |
build: { | |
files: { | |
'web/assets/js/all.min.js': ['web/assets/js/all.js'] | |
} | |
} | |
}, | |
svgmin: { // Task | |
options: { // Configuration that will be passed directly to SVGO | |
plugins: [ | |
{removeViewBox: false}, | |
{removeUselessStrokeAndFill: false} | |
] | |
}, | |
dist: { // Target | |
files: [{ // Dictionary of files | |
expand: true, // Enable dynamic expansion. | |
cwd: '_src/svg/', // Src matches are relative to this path. | |
src: ['**/*.svg'], // Actual pattern(s) to match. | |
dest: 'web/assets/images/svg/', // Destination path prefix. | |
ext: '.svg' // Dest filepaths will have this extension. | |
// ie: optimise img/src/branding/logo.svg and store it in img/branding/logo.min.svg | |
}] | |
} | |
}, | |
svg2png: { | |
all: { | |
// specify files in array format with multiple src-dest mapping | |
files: [ | |
// rasterize all SVG files in "img" and its subdirectories to "img/png" | |
{cwd: '_src/svg/', src: ['**/*.svg'], dest: 'web/assets/images/svg/png/'} | |
] | |
} | |
}, | |
compass: { // Task | |
dist: { // Target | |
options: { // Target options | |
config: 'config.rb' | |
} | |
} | |
}, | |
cssnano: { | |
options: { | |
sourcemap: false, | |
discardComments: {removeAll: true} | |
}, | |
dist: { | |
files: { | |
'web/assets/css/styles.min.css': 'web/assets/css/styles.css' | |
} | |
} | |
}, | |
watch: { | |
js: { | |
files: ['_js/*.js'], | |
tasks: ['newer:jshint', 'newer:concat', 'uglify'] | |
}, | |
image_svg: { | |
files: ['_src/svg/*.svg'], | |
tasks: ['newer:svgmin', 'newer:svg2png'] | |
}, | |
sass: { | |
files: ['_sass/**/*.scss'], | |
tasks: ['compass'] | |
}, | |
css: { | |
files: ['web/assets/css/styles.css'], | |
tasks: ['cssnano'] | |
} | |
} | |
}); | |
// Default task(s). | |
grunt.registerTask('default', ['newer:jshint', 'newer:concat', 'newer:uglify', 'newer:svgmin', 'svg2png', 'compass', 'cssnano']); | |
}; |
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
{ | |
"name": "Grunt-Setup-for-SASS-and-JS", | |
"version": "0.1.0", | |
"description": "Grunt Setup for SASS and JS", | |
"author": "Sean Cooper <sean@orderandchaoscreative.com>", | |
"license": "MIT", | |
"devDependencies": { | |
"grunt": "^0.4.x", | |
"grunt-contrib-compass": "^1.0.4", | |
"grunt-contrib-concat": "~1.0.x", | |
"grunt-contrib-jshint": "~1.0.x", | |
"grunt-contrib-uglify": "~1.0.x", | |
"grunt-contrib-watch": "~1.0.x", | |
"grunt-cssnano": "^2.0.1", | |
"grunt-newer": "^1.1.1", | |
"grunt-svg2png": "~0.2.x", | |
"grunt-svgmin": "~3.3.0", | |
"jshint-stylish": "~2.2.0", | |
"matchdep": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment