Skip to content

Instantly share code, notes, and snippets.

@bradfrost
Last active July 17, 2021 15:39
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bradfrost/10906886 to your computer and use it in GitHub Desktop.
Save bradfrost/10906886 to your computer and use it in GitHub Desktop.
Starter Kit Gruntfile.js
module.exports = function(grunt) {
// Configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'source/js/libs/*.js', // All JS in the libs folder
'source/js/init.js' // This specific file
],
dest: 'public/js/production.js'
}
},
uglify: {
build: {
src: 'public/js/production.js',
dest: 'public/js/production.min.js'
}
},
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'public/css/style.css': 'source/css/style.scss',
'public/styleguide/css/styleguide.css': 'public/styleguide/css/styleguide.scss',
'public/styleguide/css/styleguide-specific.css': 'public/styleguide/css/styleguide-specific.scss'
}
}
},
autoprefixer: {
single_file: {
src: 'public/css/style.css',
dest: 'public/css/style.css'
}
},
shell: {
patternlab: {
command: "php core/builder.php -gp"
}
},
watch: {
html: {
files: ['source/_patterns/**/*.mustache', 'source/_patterns/**/*.json', 'source/_data/*.json'],
tasks: ['shell:patternlab'],
options: {
livereload: true,
spawn: false
}
},
scripts: {
files: ['source/js/*.js'],
tasks: ['concat', 'uglify'],
options: {
livereload: true,
spawn: false
}
},
css: {
files: ['source/css/*.scss', 'source/css/**/*.scss', 'public/styleguide/css/**/*.scss'],
tasks: ['sass','autoprefixer'],
options: {
livereload: true,
spawn: false
}
}
}
});
// Plugins
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-shell');
// Tasks
grunt.registerTask('default', ['concat', 'uglify', 'sass', 'watch', 'autoprefixer', 'shell:patternlab']);
};
@patik
Copy link

patik commented May 30, 2014

With watch, as with most grunt plugins, you can move options to the top level instead of repeating them in each task.

watch: {
    options: {
        livereload: true,
        spawn: false
    },
    html: {
        files: [],
        tasks: []
    },
    scripts: {
        files: [],
        tasks: []
    },
    css: {
        files: [],
        tasks: []
    }
}

You can still override them within each task if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment