Last active
March 15, 2017 21:21
-
-
Save pejicbgd/79a896c783905a1c313b to your computer and use it in GitHub Desktop.
Example of gruntfile.js and package.json file for automated workflow
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) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
uglify: { | |
options: { | |
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %>' | |
}, | |
build: { | |
src: 'path-to-source', | |
dest: 'path-to-destination' | |
} | |
}, | |
//compile sass files | |
sass: { | |
dist: { | |
files: { | |
'path-to-css-file' : 'path-to-scss-file', | |
'path-to-css-file' : 'path-to-scss-file' | |
} | |
} | |
}, | |
//minimize css file(s) | |
cssmin: { | |
options: { | |
shorthandCompacting: false, | |
roundingPrecision: -1 | |
}, | |
target: { | |
files: { | |
'path-to-destination': ['path-to-source-files'] | |
} | |
} | |
}, | |
//watch files for changes | |
watch: { | |
css: { | |
files: ['css or sass files to watch'], | |
tasks: ['sass', 'cssmin'] | |
}, | |
js:{ | |
files: 'path to watch', | |
tasks: ['uglify'] | |
} | |
}, | |
//use "copy" package to copy files installed by bower, | |
//run it manually after initial bower install, or whenever bower packages are updated | |
copy: { | |
main: { | |
files: [ | |
{ | |
src: ['path-to-source-files'], | |
dest: 'path-to-destination', | |
filter: 'isFile' | |
}, | |
{ | |
src: ['path-to-source-files'], | |
dest: 'path-to-destination' | |
} | |
] | |
} | |
}, | |
//concatenate css or js files | |
concat: { | |
dist: { | |
/*src: [array of files to be concatenated], | |
dest: 'destination file'*/ | |
} | |
}, | |
//run js hint on file prior to and after concat | |
jshint: { | |
beforeconcat: ['path-to-files-before-concat'], | |
afterconcat: ['path-to-concatinated-file'] | |
} | |
}); | |
//require all tasks from installed packages | |
require('load-grunt-tasks')(grunt); | |
//register default task | |
grunt.registerTask('default', ['watch', 'sass', 'uglify', 'cssmin', 'concat', 'jshint']); | |
//be sure not to give task the same name as package | |
//seen some bugs caused by this | |
grunt.registerTask('transfer', ['copy']); | |
}; |
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": "app", | |
"version": "1.0.0", | |
"description": "Short description of your work", | |
"main": "index.html", | |
"repository": { | |
"type": "git", | |
"url": "path-to-your-repo" | |
}, | |
"keywords": [ ], | |
"author": "Pejic Ivan", | |
"license": "ISC", | |
"devDependencies": { | |
"grunt": "^0.4.5", | |
"grunt-contrib-copy": "^1.0.0", | |
"grunt-contrib-concat": "^1.0.0", | |
"grunt-contrib-cssmin": "^1.0.1", | |
"grunt-contrib-jshint": "^1.0.0", | |
"grunt-contrib-sass": "^1.0.0", | |
"grunt-contrib-uglify": "^1.0.1", | |
"grunt-contrib-watch": "^1.0.0", | |
"load-grunt-tasks": "^3.4.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment