Skip to content

Instantly share code, notes, and snippets.

@alexbeletsky
Created August 19, 2015 13:52
Show Gist options
  • Save alexbeletsky/3938fe99ca9de52f4384 to your computer and use it in GitHub Desktop.
Save alexbeletsky/3938fe99ca9de52f4384 to your computer and use it in GitHub Desktop.
var envify = require('envify/custom');
module.exports = function (grunt) {
require('time-grunt')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dev: {
files: {
'source/build/app.js': ['source/js/app.js']
},
options: {
browserifyOptions: {
debug: true
},
transform: [envify({
APP_ENV: 'development'
})]
},
},
stage: {
files: {
'source/build/app.js': ['source/js/app.js']
},
options: {
transform: [envify({
APP_ENV: 'staging'
})]
}
},
prod: {
files: {
'source/build/app.js': ['source/js/app.js']
},
options: {
transform: [envify({
APP_ENV: 'production'
})]
}
}
},
compass: {
dev: {
options: {
sassDir: 'source/sass',
cssDir: 'source/css',
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> (<%= pkg.homepage %>) */',
mangle: false
},
main: {
files: {
'public/build/app.js': ['source/build/app.js']
}
}
},
jshint: {
files: ['source/**/*.js']
},
cssmin: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> (<%= pkg.homepage %>) */'
},
minify:{
files: {
'public/css/main.css': ['source/css/main.css']
}
}
},
watch: {
src: {
files: ['source/**/*.js', 'source/**/*.json', '!source/build/app.js'],
tasks: ['jshint', 'browserify:dev'],
options: {
livereload: true
}
},
sass: {
files: 'source/sass/*.scss',
tasks: ['compass'],
options: {
livereload: true
}
},
html: {
files: ['source/**/*.html', 'source/**/*.css'],
options: {
livereload: true
}
}
},
htmlbuild: {
main: {
src: 'source/index.html',
dest: 'public/index.html'
}
},
connect: {
dev: {
options: {
base: 'source',
hostname: 'localhost',
port: 5002,
open: {
target: 'http://localhost:5002?accessToken=IiGMbd-6KPmzWPfsWGRWC8iAR5ibr68_eyUHAP6OnS0'
}
}
},
dist: {
options: {
base: 'public',
hostname: 'localhost',
port: 5003,
open: {
target: 'http://localhost:5003?accessToken=IiGMbd-6KPmzWPfsWGRWC8iAR5ibr68_eyUHAP6OnS0'
}
}
}
},
copy: {
images: {
cwd: 'source/images',
src: '**/*',
dest: 'public/images',
expand: true
},
bootstrap: {
cwd: 'source/css/bootstrap',
src: '**/*',
dest: 'public/css/bootstrap',
expand: true
},
fontello: {
cwd: 'source/css/fontello',
src: '**/*',
dest: 'public/css/fontello',
expand: true
},
fonts: {
cwd: 'source/fonts',
src: '**/*',
dest: 'public/fonts',
expand: true
},
views: {
cwd: 'source/views',
src: '**/*',
dest: 'public/views',
expand: true
},
uigrid: {
cwd: 'source/css',
src: '**/ui-grid.*',
dest: 'public/css',
expand: true
}
},
rev: {
options: {
algorithm: 'sha1',
length: 7
},
files: {
src: ['public/build/app.js', 'public/css/main.css']
}
},
usemin: {
html: 'public/index.html'
},
clean: {
build: ['public']
}
});
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-html-build');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-rev');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('dist', ['uglify', 'cssmin', 'htmlbuild', 'copy', 'rev', 'usemin']);
grunt.registerTask('build:dev', ['jshint', 'browserify:dev', 'compass']);
grunt.registerTask('build:stage', ['clean', 'browserify:stage', 'compass', 'dist']);
grunt.registerTask('build:prod', ['clean', 'browserify:prod', 'compass', 'dist']);
grunt.registerTask('start:dev', ['build:dev', 'connect:dev', 'watch']);
grunt.registerTask('start:stage', ['build:stage', 'connect:dist', 'watch']);
grunt.registerTask('start:prod', ['build:prod', 'connect:dist', 'watch']);
grunt.registerTask('default', 'start:dev');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment