Skip to content

Instantly share code, notes, and snippets.

@Nosherwan
Created November 26, 2015 05:31
Show Gist options
  • Save Nosherwan/6793844c631332519d7e to your computer and use it in GitHub Desktop.
Save Nosherwan/6793844c631332519d7e to your computer and use it in GitHub Desktop.
module.exports = function (grunt) {
var serveStatic = require('serve-static');
var LIVERELOAD_PORT = 35729; // Default port
require('load-grunt-tasks')(grunt);
grunt.initConfig(
{
clean : { //cleans the dist folder
build: {
src: ['dist/*']
}
},
browserify: { //resolves requires and then concatenates all files
dev : {
options: { //babelify will convert es6 to es5, and convert jsx to js; this step will always have to be done
transform : [
['babelify', {
presets: ['es2015', 'react']
}]
],
browserifyOptions: {
debug: true //will generate source maps for dev env (uses the doSMaps variable from above)
},
watch : true //watches for changes and rebuilds
},
files : [{
src : ['app/js/**/*.js'],
dest: 'dist/bundle.js'
}]
},
prod: {
options: { //babelify will convert es6 to es5, and convert jsx to js; this step will always have to be done
transform: [
['babelify', {
presets: ['es2015', 'react']
}]
]
},
files : [{
src : ['app/js/**/*.js'],
dest: 'dist/bundle.js'
}]
}
},
cssmin : {
options: {
shorthandCompacting: true,
roundingPrecision : -1
},
target : {
files: {
'dist/bundle.css': [
'./node_modules/bootstrap/dist/css/bootstrap.min.css',
'./style/custom.css']
}
}
},
copy : {
main: {
src : 'app/index.html',
dest: 'dist/index.html'
}
},
connect : {
options : {
port : 9001,
base: 'dist',
livereload: LIVERELOAD_PORT,
hostname : 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
require('connect-livereload')({port: LIVERELOAD_PORT}),
serveStatic('./dist')
]
}
}
}
},
watch : {
options: {
livereload: LIVERELOAD_PORT
},
files : ['dist/**/*']
}
}
);
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-webfont');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('default',
[
'clean',
'browserify:dev',
'cssmin',
'copy',
'connect:livereload',
'watch'
]
);
grunt.registerTask('build',
[
'clean',
'browserify:prod',
'cssmin',
'copy'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment