Skip to content

Instantly share code, notes, and snippets.

@jaspervalero
Created October 13, 2014 02:31
Show Gist options
  • Save jaspervalero/c5ce769b0c17778a8fa3 to your computer and use it in GitHub Desktop.
Save jaspervalero/c5ce769b0c17778a8fa3 to your computer and use it in GitHub Desktop.
Gruntfile.js w/ Mocha, Phantom.js, LiveReload (Code Example)
module.exports = function( grunt ) {
var port = 8981;
// Task config
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
clean: {
files: [ 'dist' ]
},
concat: {
dist: {
src: [ '<%= concat.dist.dest %>' ],
dest: 'dist/<%= pkg.name %>.js'
}
},
connect: {
server: {
options: {
port: port,
base: '.'
}
}
},
nodemon: {
dev: {
script: 'util/test-server.js',
options: {
watch: [ 'util' ]
}
}
},
requirejs: {
compile: {
options: {
name: 'main',
baseUrl: './app',
include:[ 'requireLib' ],
paths: {
requireLib: '../bower_components/requirejs/require',
jquery: '../bower_components/jquery/jquery.min'
},
optimize: 'none',
normalizeDirDefines : 'all' ,
insertRequire: [ 'main' ],
out: '<%= concat.dist.dest %>'
}
}
},
shell: {
'mocha-phantomjs': {
command: 'mocha-phantomjs -R spec http://localhost:8000/testrunner.html',
options: {
stdout: true,
stderr: true
}
}
},
uglify: {
dist: {
src: '<%= concat.dist.dest %>',
dest: '<%= concat.dist.dest.replace( "js", "min.js" ) %>'
}
},
watch: {
app: {
options: {
livereload: true
},
files: [ 'app/**', 'test/**', 'Gruntfile.js' ],
tasks: [ 'build' ]
}
}
});
// Use matchdep to pull in grunt dependencies
require( 'matchdep' ).filterDev( [ 'grunt-*' ] ).forEach( grunt.loadNpmTasks );
// Tasks
grunt.registerTask( 'dev', [ 'watch' ] );
grunt.registerTask( 'launchTestServer', [ 'nodemon' ] );
grunt.registerTask( 'build', [ 'shell:mocha-phantomjs', 'clean', 'requirejs', 'concat', 'uglify' ] );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment