Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Forked from anonymous/Gruntfile2.js
Created April 9, 2014 07:10
Show Gist options
  • Save shakyShane/10234545 to your computer and use it in GitHub Desktop.
Save shakyShane/10234545 to your computer and use it in GitHub Desktop.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Watch
watch: {
options: {
cwd: 'httpdocs/',
spawn: false
},
css: {
files: ['src/scss/**/**/*.scss'],
tasks: ['sass', 'autoprefixer', 'bs-reload'],
},
uglify: {
files: ['src/js/**/*.js','!**/*.min.js'],
tasks: ['uglify'],
},
concat: {
files: ['src/js/**/*.js'],
tasks: ['concat'],
}
},
// AUTOPREFIXER
autoprefixer: {
options: {
// Task-specific options go here.
// browsers - https://github.com/ai/autoprefixer#browsers
browsers: ['> 5%', 'last 2 version', 'ie 9']
},
// prefix all files
no_dest_multiple: {
src: 'httpdocs/static/css/*.css'
}
},
// BROWSER SYNC - This not needed when using the API
// https://www.npmjs.org/package/grunt-browser-sync
// browserSync: {
// dev: {
// bsFiles: {
// src : [
// 'httpdocs/static/css/*.css',
// 'httpdocs/static/js/**/*.js',
// 'httpdocs/**/*.html'
// ]
// },
// options: {
// watchTask: true,
// server: {
// baseDir: "httpdocs/"
// }
// }
// }
// },
// UGLIFY
uglify: {
build: {
// src: ['src/js/**/*.js'],
// dest: 'src/js/<%= pkg.name %>.min.js'
// We're being quite explicit
files: {
'httpdocs/src/js/dh-tabs.plugin.min.js': ['httpdocs/src/js/dh-tabs.plugin.js'],
'httpdocs/src/js/<%= pkg.name %>.min.js': ['httpdocs/src/js/<%= pkg.name %>.js'],
}
}
},
// CONCAT JS
concat: {
options: {
separator: ';',
banner: '/*! \nJS for <%= pkg.name %> - v<%= pkg.version %>\nAuthor: <%= pkg.author %>\nModified: <%= grunt.template.today("yyyy-mm-dd") %>\n */\n',
},
dist: {
// src: ['src/**/*.js'],
// dest: 'static/js/all.min.js'
// We're explicit in what files/order we concat...
src: ['httpdocs/src/js/dh-tabs.plugin.min.js','httpdocs/src/js/<%= pkg.name %>.min.js'],
dest: 'httpdocs/static/js/app.min.js'
}
},
// SASS
sass: {
dist: {
options: {
style: 'compressed',
banner: '/*!\n@project: <%= pkg.name %> by <%= pkg.author %>\n@modified: <%= grunt.template.today("yyyy-mm-dd") %>\n*/\n'
},
files: {
'httpdocs/static/css/style.min.css':'httpdocs/src/scss/style.scss'
}
}
}
});
// Start BrowserSync via the API
var bs;
grunt.registerTask("bs-start", function () {
var browserSync = require("browser-sync");
bs = browserSync.init([
'httpdocs/static/js/**/*.js',
'httpdocs/**/*.html'
], {
server: {
baseDir: "httpdocs/"
}
})
});
// Fire file-change events manually for greater control
grunt.registerTask("bs-reload", function () {
bs.events.emit("file:changed", {path: "style.css"});
bs.events.emit("file:changed", {path: "style2.css"});
});
// Load the plugin that provides the "uglify" task.
// grunt.loadNpmTasks('grunt-XXXX');
require('load-grunt-tasks')(grunt);
// Default task(s).
grunt.registerTask('default', ['bs-start', 'watch']);
};
@shakyShane
Copy link
Author

For the above task to work, notice that spawn; false is set in the watch task & you'll have to run npm install browser-sync

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