Skip to content

Instantly share code, notes, and snippets.

@leon
Created September 5, 2013 07:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leon/6446911 to your computer and use it in GitHub Desktop.
Save leon/6446911 to your computer and use it in GitHub Desktop.
Advanced Grunt Setup
{
"directory": "bower_components",
"json": "bower.json"
}
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": false,
"smarttabs": true,
"white": false,
"globals": {
"$": false,
"angular": false,
"browser": false,
"repeater": false,
"element": false,
"inject": false,
"afterEach": false,
"beforeEach": false,
"confirm": false,
"context": false,
"describe": false,
"ddescribe": false,
"expect": false,
"it": false,
"iit": false,
"jasmine": false,
"JSHINT": false,
"mostRecentAjaxRequest": false,
"qq": false,
"runs": false,
"spyOn": false,
"spyOnEvent": false,
"waitsFor": false,
"xdescribe": false,
"URI": false,
"_": false
}
}
{
"name": "site",
"version": "0.0.1",
"dependencies": {
"es5-shim": "~2.1.0",
"json3": "~3.2.5",
"lodash": "~1.3.1",
"angular": "1.2.0rc1",
"angular-i18n": "1.2.0rc1",
"angular-resource": "1.2.0rc1",
"angular-sanitize": "v1.2.0-rc.1",
"angular-animate": "1.2.0rc1",
"angular-ui-router": "~0.2.0",
"angular-cache": "~1.1.0",
"angular-slider": "~0.1.6",
"angular-ui-utils": "~0.0.4",
"angular-mocks": "1.2.0rc1",
"bootstrap": "~3.0.0",
"angular-bootstrap": "https://github.com/angular-ui/bootstrap.git#bootstrap3_bis", // needs custom building at the moment to get bootstrap 3 functionality
"font-awesome": "~3.2.1",
"d3": "~3.3.2",
"r2d3": "~0.2.0"
}
}
/**
* This file/module contains all configuration for the Grunt build.
*/
module.exports = {
src: {
dir: 'src',
js: ['src/**/*.js', '!src/**/*.spec.js'],
jsUnit: 'src/**/*.spec.js',
tpl: 'src/**/*.tpl.html',
lessDir: 'src/less',
less: 'src/**/*.less',
lessMain: 'src/less/main.less',
html: 'src/**/*.html',
htmlMain: 'src/index.html',
components: [
'bower_components/angular/angular.js',
'bower_components/angular-i18n/angular-locale_sv-se.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
//'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-bootstrap/dist/ui-bootstrap-tpls-0.6.0-SNAPSHOT.js',
'bower_components/angular-cache/dist/angular-cache-1.1.0.js',
'bower_components/angular-ui-utils/modules/keypress/keypress.js',
'bower_components/lodash/dist/lodash.js'
],
ieshim: [
'bower_components/es5-shim/es5-shim.min.js',
'bower_components/json3/lib/json3.min.js'
]
},
dist: {
dir: '../static/ui',
js: '../static/ui/js/app.js',
tpl: '../static/ui/js/app.tpl.js',
components: '../static/ui/js/components.js',
ieshim: '../static/ui/js/ieshim.js',
less: '../static/ui/css/app.css',
fonts: '../static/ui/font',
// Custom export till pub
html: '../WEB-INF/sites/www/templates/index.html'
}
};
'use strict';
/*var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var modRewrite = require('connect-modrewrite');
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};*/
module.exports = function (grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
/**
* Load in our build configuration file.
*/
var userDefinedConfig = require('./Gruntfile.config.js');
grunt.initConfig({
// Load Config
config: userDefinedConfig,
// Testing
karma: {
unit: {
configFile: 'karma.conf.js',
background: true
},
continuos: {
configFile: 'karma.conf.js',
singleRun: true
}
},
// Validation
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= config.src.js %>',
'<%= config.src.jsUnit %>'
]
},
// Developing
watch: {
gruntfile: {
files: ['Gruntfile.js'],
tasks: ['build']
},
js: {
files: ['<%= config.src.js %>', '<%= config.src.jsUnit %>'],
tasks: ['concat:dev', 'jshint', 'karma:unit:run']
},
less: {
files: ['<%= config.src.less %>'],
tasks: ['less:dev']
},
html: {
files: ['<%= config.src.html %>'],
tasks: ['html2js']
},
htmlMain: {
files: ['<%= config.src.htmlMain %>'],
tasks: ['copy:alterhtml']
},
livereload: {
options: {
livereload: true
},
files: ['<%= config.dist.dir %>/**/*']
}
},
// Building
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= config.dist.dir %>/*',
'!<%= config.dist.dir %>/.git*'
]
}]
}
},
less: {
options: {
paths: [
'<%= config.src.lessDir %>'
]
},
dev: {
files: {
'<%= config.dist.less %>': '<%= config.src.lessMain %>'
}
},
dist: {
options: {
yuicompress: true
},
files: {
'<%= config.dist.less %>': '<%= config.src.lessMain %>'
}
}
},
concat: {
dev: {
files: {
'<%= config.dist.js %>': '<%= config.src.js %>'
}
},
dist: {
files: {
'<%= config.dist.components %>': '<%= config.src.components %>',
'<%= config.dist.ieshim %>': '<%= config.src.ieshim %>'
}
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.src.dir %>',
dest: '<%= config.dist.dir %>',
src: [
'**/*.{ico,png,jpg,gif,txt,ttf,eot,svg,woff,otf}',
'.htaccess'
]
}]
},
alterhtml: {
src: '<%= config.src.htmlMain %>',
dest: '<%= config.dist.html %>'
},
glyficons: {
files: [{
expand: true,
dot: true,
cwd: 'bower_components/bootstrap/fonts',
dest: '<%= config.dist.fonts %>',
src: ['*.{ttf,eot,svg,woff,otf}']
}]
},
fontawesome: {
files: [{
expand: true,
dot: true,
cwd: 'bower_components/font-awesome/font',
dest: '<%= config.dist.fonts %>',
src: ['*.{ttf,eot,svg,woff,otf}']
}]
},
d3: {
src: 'bower_components/d3/d3.min.js',
dest: '<%= config.dist.dir %>/js/d3.js'
},
r2d3: {
src: 'bower_components/r2d3/r2d3.min.js',
dest: '<%= config.dist.dir %>/js/r2d3.js'
}
},
ngmin: {
dist: {
files: [{
expand: true,
cwd: '<%= config.dist.dir %>',
src: '*.js',
dest: '<%= config.dist.html %><%= config.dist.dir %>'
}]
}
},
uglify: {
dist: {
files: {
'<%= config.dist.js %>': '<%= config.src.js %>',
'<%= config.dist.tpl %>': '<%= config.dist.tpl %>'
},
options: {
compress: true
}
}
},
html2js: {
app: {
options: {
base: '<%= config.src.dir %>',
module: 'app.templates'
},
src: ['<%= config.src.tpl %>'],
dest: '<%= config.dist.tpl %>',
}
}
});
grunt.registerTask('test', [
'jshint',
'karma:continuos'
]);
grunt.registerTask('server', [
'less:dev',
'concat',
'copy',
'html2js',
'watch',
]);
grunt.registerTask('testserver', [
'karma:unit',
'watch:js',
'karma:unit:run'
]);
grunt.registerTask('build', [
//'clean:dist',
'less:dist',
'concat',
'copy',
'html2js',
'ngmin:dist',
'uglify:dist'
]);
grunt.registerTask('default', [
'test',
'build'
]);
};
module.exports = function(config) {
var userDefinedConfig = require('./Gruntfile.config.js');
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// list of files / patterns to load in the browser
files: [].concat(
userDefinedConfig.src.components,
'bower_components/angular-mocks/angular-mocks.js',
userDefinedConfig.src.js[0],
userDefinedConfig.dist.tpl,
userDefinedConfig.src.jsUnit
),
frameworks: ['jasmine'],
plugins: ['karma-jasmine', 'karma-firefox-launcher', 'karma-chrome-launcher'],
/**
* How to report, by default.
*/
reporters: 'dots',
/**
* On which port should the browser connect, on which port is the test runner
* operating, and what is the URL path for the browser to use.
*/
port: 9018,
runnerPort: 9100,
urlRoot: '/',
/**
* Disable file watching by default.
*/
autoWatch: false,
/**
* The list of browsers to launch to test on. This includes only "Firefox" by
* default, but other browser names include:
* Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
*
* Note that you can also use the executable name of the browser, like "chromium"
* or "firefox", but that these vary based on your operating system.
*
* You may also leave this blank and manually navigate your browser to
* http://localhost:9018/ when you're running tests. The window/tab can be left
* open and the tests will automatically occur there during the build. This has
* the aesthetic advantage of not launching a browser every time you save.
*/
browsers: [
'Chrome'
]
});
};
{
"name": "site",
"version": "0.0.1",
"author": "Leon",
"dependencies": {},
"devDependencies": {
"matchdep": "~0.1.2",
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-less": "~0.5.0",
"grunt-karma": "~0.6.1",
"grunt-ngmin": "0.0.3",
"grunt-html2js": "~0.1.6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment