Last active
August 29, 2015 13:59
-
-
Save anareyna/10666922 to your computer and use it in GitHub Desktop.
Grunt common tasks
This file contains hidden or 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'), | |
| // clean | |
| clean: { | |
| options: {force: true}, | |
| build: { | |
| src: [cfg.js_compiled_source_path] | |
| } | |
| }, | |
| //coffee | |
| coffee: { | |
| glob_to_multiple: { | |
| options: { | |
| bare: true | |
| }, | |
| expand: true, | |
| cwd: cfg.coffee_source_path, // all the source | |
| src: ['**/*.coffee','!**/_*.coffee'], // Pattern to match, relative to the cwd. | |
| dest: cfg.js_compiled_source_path, | |
| ext: '.js' | |
| } | |
| }, | |
| //concat | |
| concat: { | |
| options: { | |
| stripBanners: false | |
| } | |
| }, | |
| //uglify | |
| uglify: { | |
| options: { | |
| banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("dd/mm/yyyy") %> */\n', | |
| mangle: false, | |
| compress: { | |
| drop_console: true | |
| } | |
| }, | |
| js: { | |
| files: [{ | |
| expand: true, | |
| cwd: cfg.js_source_path, // all the source | |
| src: '**/*.js', // pattern relative to cwd | |
| dest: cfg.js_min_source_path, | |
| }] | |
| } | |
| }, | |
| //jade | |
| jade: { | |
| compile: { | |
| options: { | |
| data: {} | |
| }, | |
| files: [{ | |
| expand: true, | |
| cwd: cfg.jademobile_source_path, | |
| src: [ '**/*.jade', '!config/*.jade', '!layout/*.jade', '!render/*.jade'], | |
| dest: cfg.jade_compiled_source_path, | |
| ext: '.html' | |
| }] | |
| } | |
| }, | |
| //watch | |
| watch: { | |
| javascript: { | |
| files: [cfg.coffee_source_path+'modules/**/*.coffee'], | |
| tasks: ['js'], | |
| options: { | |
| interrupt: true | |
| } | |
| }, | |
| }, | |
| //copy | |
| copy: { | |
| main: { | |
| src: '../../public/f/img_src/favicon.ico', | |
| dest: '../../public/f/img/favicon.ico' | |
| }, | |
| }, | |
| //imagemin // add this to package.json "grunt-contrib-imagemin": "0.4.1", "grunt-contrib-copy": "~0.4.1", | |
| imagemin: { | |
| dynamic: { | |
| options: { | |
| optimizationLevel: 3 | |
| }, // Another target | |
| files: [{ | |
| expand: true, // Enable dynamic expansion | |
| cwd: '../../public/f/img_src', // Src matches are relative to this path | |
| src: ['**/*.{png,jpg,gif}'], // Actual patterns to match | |
| dest: '../../public/f/img' // Destination path prefix | |
| }] | |
| } | |
| }, | |
| sprite:{ | |
| all: { | |
| src: '../../public/f/sprite/*.png', | |
| destImg: '../../public/f/styflux/library/styflux/utils/sprites1.png',//'../../public/f/sprite/resultado/spritesheet1.png', | |
| destCSS: '../../public/f/styflux/library/styflux/utils/sprites.styl', | |
| algorithm: 'binary-tree' | |
| } | |
| }, | |
| //jshint | |
| jshint: { | |
| options: { | |
| jshintrc : 'grunt/jshint/.jshintrc', | |
| "smarttabs" : true | |
| }, | |
| js: [cfg.js_source_path+'**/*.js', '!'+cfg.js_source_path+'abautos/*.js', '!'+cfg.js_source_path+'libs/*.js', '!'+cfg.js_source_path+'libs/utils/*.js', '!'+cfg.js_source_path+'libs/jquery/*.js', '!'+cfg.js_source_path+'libs/yoson/old_modules/*.js', '!'+cfg.js_source_path+'libs/yoson/data/*.js'] | |
| }, | |
| //replace | |
| replace: { | |
| dist: { | |
| options: { | |
| patterns: [ | |
| { | |
| match: /version/g, | |
| replacement: version | |
| } | |
| ] | |
| }, | |
| files: [ | |
| {expand: true, flatten: true, src: [cfg.css_compiled_source_path+'*.css'], dest: cfg.css_compiled_source_path} | |
| ] | |
| } | |
| }, | |
| js2coffee: { | |
| options: { | |
| indent : " " | |
| }, | |
| // Example: this target compiles a single file from JavaScript to CofeeScript | |
| single: { | |
| src: cfg.js_to_coffee_compiled + 'main.js', | |
| dest: cfg.js_to_coffee_compiled + 'main.coffee' | |
| } | |
| } | |
| }); | |
| //loadNpmTasks | |
| grunt.loadNpmTasks('grunt-contrib-clean'); | |
| grunt.loadNpmTasks('grunt-contrib-coffee'); | |
| grunt.loadNpmTasks('grunt-contrib-concat'); | |
| grunt.loadNpmTasks('grunt-contrib-copy'); | |
| grunt.loadNpmTasks('grunt-spritesmith'); | |
| grunt.loadNpmTasks('grunt-contrib-cssmin'); | |
| grunt.loadNpmTasks('grunt-contrib-imagemin'); | |
| grunt.loadNpmTasks('grunt-contrib-jshint'); | |
| grunt.loadNpmTasks('grunt-contrib-uglify'); | |
| grunt.loadNpmTasks('grunt-contrib-watch'); | |
| grunt.loadNpmTasks('grunt-js2coffee'); | |
| grunt.loadNpmTasks('grunt-replace'); | |
| // load tasks | |
| grunt.task.loadTasks('grunt/custom_tasks/'); | |
| //registerTask | |
| grunt.registerTask('cafe', ['clean', 'coffee']); | |
| grunt.registerTask('js_source', ['concatenation', 'concat']); | |
| grunt.registerTask('javascript', ['js_source', 'jshint']); //, 'uglify']); | |
| grunt.registerTask('js', ['cafe', 'javascript']); //, 'uglify']); | |
| grunt.registerTask('imgmin', ['imagemin', 'copy']); | |
| // Run Default task(s). | |
| grunt.registerTask('default', ['cafe', 'javascript']); // 'replace']); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment