Created
April 2, 2014 20:31
-
-
Save anonymous/9942507 to your computer and use it in GitHub Desktop.
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) { | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
// Watch | |
watch: { | |
options: { | |
cwd: 'httpdocs/' | |
}, | |
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']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: you may need to run
npm install browser-sync --save-dev
before using this, not grunt-browser-sync!This Gruntfile.js shows how you can use BrowserSync via the api for greater control.
You can see on line 14 we call a custom task AFTER all previous CSS tasks.
on lines 107-108 we watch other files as normal (ones that don't have multiple tasks assigned to them) and then provide config as normal.
Finally on line 127 we run browserSync followed by the watch task.