Skip to content

Instantly share code, notes, and snippets.

@pandauxstudio
Created June 28, 2017 12:54
Show Gist options
  • Save pandauxstudio/aab9711d7f3e6b86678c197a05c7a465 to your computer and use it in GitHub Desktop.
Save pandauxstudio/aab9711d7f3e6b86678c197a05c7a465 to your computer and use it in GitHub Desktop.
module.exports = function(grunt) {
// https://www.sitepoint.com/writing-awesome-build-script-grunt/
// http://paislee.io/testing-angularjs-with-grunt-karma-and-jasmine/
grunt.loadNpmTasks('grunt-karma');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
build: {
src: ['build']
},
stylesheets: {
src: ['build/**/*.css', '!build/application.css']
},
scripts: {
src: ['build/**/*.js', '!build/application.min.js']
},
},
karma: {
unit: {
options: {
frameworks: ['jasmine'],
singleRun: true,
browsers: ['PhantomJS'],
//files: ['public/components/angular/angular.js', 'public/components/angular-mocks/angular-mocks.js', 'src/js/**/*.js']
files: ['test/**/*.js']
}
}
},
uglify: {
build: {
options: {
mangle: true
},
files: {
'build/application.min.js': ['build/**/*.js']
}
}
},
qunit: {
files: ['test/**/*.html']
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
}
}
},
copy: {
build: {
cwd: '.',
src: ['css/*.css', 'fonts/**/*', 'webfonts/**/*', 'images/**/*', 'javascript/**/*.js'],
dest: 'build',
expand: true
},
},
watch: {
stylesheets: {
files: 'scss/**/*.scss',
tasks: ['stylesheets']
},
scripts: {
files: 'javascript/**/*.js',
tasks: ['scripts']
},
copy: {
files: ['css/*.css', '!scss/**/*.scss'],
tasks: ['copy']
}
},
sass: {
build: {
files: [{
expand: true,
cwd: 'scss',
src: ['*.scss'],
dest: 'build/css',
ext: '.css'
}]
}
},
css: {
files: ['scss/*.scss'],
tasks: ['stylesheets']
},
cssmin: {
build: {
options: {
restructuring: false
},
files: {
'build/application.css': [ 'build/css/**/*.css' ]
}
}
},
autoprefixer: {
build: {
expand: true,
cwd: 'build',
src: ['css/*.css'],
dest: 'build'
}
}
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
//grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask(
'stylesheets',
'Compiles the stylesheets.',
['sass', 'cssmin', 'clean:stylesheets']
);
grunt.registerTask(
'scripts',
'Compiles the JavaScript files.',
['uglify', 'clean:scripts']
);
grunt.registerTask(
'build',
'Compiles all of the assets and copies the files to the build directory.',
['clean:build', 'copy', 'stylesheets', 'scripts']
);
grunt.registerTask('test', ['jshint', 'karma']);
grunt.registerTask(
'default',
'Watches the project for changes, automatically builds them and runs a server.',
['build', 'watch']
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment