Last active
August 29, 2015 14:08
-
-
Save austinkeeley/222f4d83c517dded6ce8 to your computer and use it in GitHub Desktop.
Grunt Starter
This file contains hidden or 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) { | |
// Load our plugins | |
grunt.loadNpmTasks('grunt-concurrent'); | |
grunt.loadNpmTasks('grunt-contrib-connect'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-cssmin'); | |
// Configurable paths | |
var config = { | |
app: 'app', | |
dist: 'dist' | |
}; | |
// Project configuration. | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
config: config, | |
clean: { | |
dist: { | |
files: [{ | |
dot: true, | |
src: [ | |
'.tmp', | |
'<%= config.dist %>/*', | |
'!<%= config.dist %>/.git*' | |
] | |
}] | |
}, | |
server: '.tmp' | |
}, | |
concurrent: { | |
server: [ | |
'copy:styles' | |
] | |
}, | |
copy: { | |
dist: { | |
files: [{ | |
expand: true, | |
dot: true, | |
cwd: '<%= config.app %>', | |
dest: '<%= config.dist %>', | |
src: [ | |
'*.{ico,png,txt}', | |
'.htaccess', | |
'images/{,*/}*.webp', | |
'{,*/}*.html', | |
'styles/fonts/{,*/}*.*' | |
] | |
}, { | |
expand: true, | |
dot: true, | |
cwd: 'bower_components/bootstrap/dist', | |
src: ['fonts/*.*'], | |
dest: '<%= config.dist %>' | |
}] | |
}, | |
styles: { | |
expand: true, | |
dot: true, | |
cwd: '<%= config.app %>/styles', | |
dest: '.tmp/styles/', | |
src: '{,*/}*.css' | |
} | |
}, | |
connect: { | |
options: { | |
port: 9000, | |
open: true, | |
debug: true, | |
livereload: 35729, | |
// Change this to '0.0.0.0' to access the server from outside | |
hostname: '0.0.0.0' | |
}, | |
livereload: { | |
options: { | |
middleware: function(connect) { | |
return [ | |
connect.static('.tmp'), | |
connect().use('/bower_components', connect.static('./bower_components')), | |
connect.static(config.app) | |
]; | |
} | |
} | |
}, | |
test: { | |
options: { | |
open: false, | |
port: 9001, | |
middleware: function(connect) { | |
return [ | |
connect.static('.tmp'), | |
connect.static('test'), | |
connect().use('/bower_components', connect.static('./bower_components')), | |
connect.static(config.app) | |
]; | |
} | |
} | |
}, | |
}, | |
cssmin: { | |
dist: { | |
files: { | |
'<%= config.dist %>/styles/main.css': [ | |
'.tmp/styles/{,*/}*.css', | |
'<%= config.app %>/styles/{,*/}*.css'] | |
} | |
} | |
}, | |
jshint: { | |
all: ['Gruntfile.js', '<%= config.app %>/scripts'] | |
}, | |
uglify: { | |
options: { | |
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' | |
}, | |
build: { | |
src: '<%= config.app %>/scripts/*.js', | |
dest: '<%=config.dist %>/scripts/<%= pkg.name %>.min.js' | |
} | |
}, | |
watch: { | |
bower: { | |
files: ['bower.json'], | |
tasks: ['bowerInstall'] | |
}, | |
js: { | |
files: ['<%= config.app %>/scripts/{,*/}*.js'], | |
tasks: ['jshint'], | |
options: { | |
livereload: true | |
} | |
}, | |
jstest: { | |
files: ['test/spec/{,*/}*.js'], | |
tasks: ['test:watch'] | |
}, | |
gruntfile: { | |
files: ['Gruntfile.js'] | |
}, | |
styles: { | |
files: ['<%= config.app %>/styles/{,*/}*.css'], | |
tasks: ['newer:copy:styles', 'autoprefixer'] | |
}, | |
livereload: { | |
options: { | |
livereload: '<%= connect.options.livereload %>' | |
}, | |
files: [ | |
'<%= config.app %>/{,*/}*.html', | |
'.tmp/styles/{,*/}*.css', | |
'<%= config.app %>/images/{,*/}*' | |
] | |
} | |
} | |
}); | |
// Default task(s). | |
grunt.registerTask('default', ['uglify']); | |
grunt.registerTask('serve', function (target) { | |
if (target === 'dist') { | |
return grunt.task.run(['build', 'connect:dist:keepalive']); | |
} | |
grunt.task.run([ | |
'clean:server', | |
'concurrent:server', | |
'connect:livereload', | |
'watch' | |
]); | |
}); | |
grunt.registerTask('build', [ | |
'clean:dist', | |
'cssmin', | |
'uglify', | |
'copy:dist', | |
]); | |
}; |
This file contains hidden or 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
{ | |
"name": "your-app-name", | |
"version": "0.0.1", | |
"devDependencies": { | |
"grunt": "~0.4.5", | |
"grunt-contrib-jshint": "~0.10.0", | |
"grunt-contrib-uglify": "~0.5.0", | |
"grunt-contrib-watch": "^0.6.1", | |
"grunt-contrib-copy": "^0.7.0", | |
"grunt-wiredep": "^1.9.0", | |
"grunt-contrib-clean": "^0.6.0", | |
"grunt-concurrent": "^1.0.0", | |
"grunt-contrib-connect": "^0.8.0", | |
"grunt-contrib-concat": "~0.3.0", | |
"grunt-contrib-cssmin": "~0.9.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment