Skip to content
Browse files

Split Grunt config into per-task files.

1 parent 7581082 commit 5a2980a7818957cbaeedcd7552af9ce54e05e3fb @cowboy committed
View
117 Gruntfile.js
@@ -1,121 +1,14 @@
module.exports = function(grunt) {
+ // Initialize config.
grunt.initConfig({
- jshint: {
- config: {
- options: {jshintrc: '.jshintrc'},
- src: ['Gruntfile.js', 'config/**/*.js'],
- },
- app: {
- options: {jshintrc: 'app/.jshintrc'},
- src: ['app/**/*.js'],
- },
- },
- clean: {
- build: ['build'],
- },
- symlink: {
- dev: {
- src: ['*', '!build'],
- dest: 'build/wwwroot',
- expand: true,
- filter: 'isDirectory',
- }
- },
- jade: {
- options: {
- data: {
- config: require('./config/app'),
- target: '<%= grunt.task.current.target %>',
- },
- },
- dev: {
- expand: true,
- cwd: 'app/pages',
- src: '*.jade',
- dest: 'build/wwwroot',
- ext: '.html',
- },
- prod: '<%= jade.dev %>',
- },
- stylus: {
- dev: {
- options: {compress: false},
- files: [{src: 'app/css/app.styl', dest: 'build/wwwroot/app.css'}],
- },
- prod: {
- files: '<%= stylus.dev.files %>',
- },
- },
- requirejs: {
- prod: {
- options: {
- baseUrl: '.',
- mainConfigFile: 'app/config/requirejs.js',
- deps: ['app/app'],
- insertRequire: ['app/app'],
- name: 'bower_components/almond/almond',
- out: 'build/wwwroot/app.js',
- optimize: 'uglify2',
- generateSourceMaps: true,
- preserveLicenseComments: false,
- },
- },
- },
- connect: {
- options: {
- hostname: '*',
- base: 'build/wwwroot',
- },
- dev: {},
- prod: {
- options: {
- keepalive: true,
- },
- },
- },
- watch: {
- livereload: {
- options: {
- livereload: true,
- },
- files: ['app/**/*.{js,hbs}', 'build/wwwroot/*'],
- tasks: [],
- },
- jshint: {
- files: ['<%= jshint.config.src %>', '<%= jshint.app.src %>'],
- tasks: ['jshint']
- },
- jade: {
- files: ['app/pages/*.jade', 'config/**/*'],
- tasks: ['jade:dev'],
- },
- stylus: {
- files: ['<%= stylus.dev.files[0].src %>'],
- tasks: ['stylus:dev'],
- },
- },
- 'gh-pages': {
- site: {
- options: {
- base: 'build/wwwroot',
- clone: 'build/gh-pages',
- },
- src: ['**/*'],
- },
- },
+ pkg: require('./package.json'),
@cowboy Owner
cowboy added a note

This wasn't needed, but just exists as an example. grunt.initConfig() doesn't really even need to be called in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
});
- grunt.loadNpmTasks('grunt-contrib-requirejs');
- grunt.loadNpmTasks('grunt-contrib-watch');
- grunt.loadNpmTasks('grunt-contrib-jade');
- grunt.loadNpmTasks('grunt-contrib-stylus');
- grunt.loadNpmTasks('grunt-contrib-connect');
- grunt.loadNpmTasks('grunt-contrib-jshint');
- grunt.loadNpmTasks('grunt-contrib-clean');
- grunt.loadNpmTasks('grunt-contrib-symlink');
- grunt.loadNpmTasks('grunt-gh-pages');
+ // Load per-task config from separate files.
+ grunt.loadTasks('grunt');
+ // Register alias tasks.
grunt.registerTask('build',
'Build site files for testing or deployment.',
['jshint', 'clean', 'jade:prod', 'requirejs:prod', 'stylus:prod']);
View
9 grunt/contrib-clean.js
@@ -0,0 +1,9 @@
+module.exports = function(grunt) {
+
+ grunt.config('clean', {
+ build: ['build'],
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+};
View
18 grunt/contrib-connect.js
@@ -0,0 +1,18 @@
+module.exports = function(grunt) {
+
+ grunt.config('connect', {
+ options: {
+ hostname: '*',
+ base: 'build/wwwroot',
+ },
+ dev: {},
+ prod: {
+ options: {
+ keepalive: true,
+ },
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-connect');
+
+};
View
22 grunt/contrib-jade.js
@@ -0,0 +1,22 @@
+module.exports = function(grunt) {
+
+ grunt.config('jade', {
+ options: {
+ data: {
+ config: require('../config/app'),
+ target: '<%= grunt.task.current.target %>',
+ },
+ },
+ dev: {
+ expand: true,
+ cwd: 'app/pages',
+ src: '*.jade',
+ dest: 'build/wwwroot',
+ ext: '.html',
+ },
+ prod: '<%= jade.dev %>',
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-jade');
+
+};
View
16 grunt/contrib-jshint.js
@@ -0,0 +1,16 @@
+module.exports = function(grunt) {
+
+ grunt.config('jshint', {
+ config: {
+ options: {jshintrc: '.jshintrc'},
+ src: ['Gruntfile.js', 'config/**/*.js'],
+ },
+ app: {
+ options: {jshintrc: 'app/.jshintrc'},
+ src: ['app/**/*.js'],
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+
+};
View
21 grunt/contrib-requirejs.js
@@ -0,0 +1,21 @@
+module.exports = function(grunt) {
+
+ grunt.config('requirejs', {
+ prod: {
+ options: {
+ baseUrl: '.',
+ mainConfigFile: 'app/config/requirejs.js',
+ deps: ['app/app'],
+ insertRequire: ['app/app'],
+ name: 'bower_components/almond/almond',
+ out: 'build/wwwroot/app.js',
+ optimize: 'uglify2',
+ generateSourceMaps: true,
+ preserveLicenseComments: false,
+ },
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-requirejs');
+
+};
View
15 grunt/contrib-stylus.js
@@ -0,0 +1,15 @@
+module.exports = function(grunt) {
+
+ grunt.config('stylus', {
+ dev: {
+ options: {compress: false},
+ files: [{src: 'app/css/app.styl', dest: 'build/wwwroot/app.css'}],
+ },
+ prod: {
+ files: '<%= stylus.dev.files %>',
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-stylus');
+
+};
View
14 grunt/contrib-symlink.js
@@ -0,0 +1,14 @@
+module.exports = function(grunt) {
+
+ grunt.config('symlink', {
+ dev: {
+ src: ['*', '!build'],
+ dest: 'build/wwwroot',
+ expand: true,
+ filter: 'isDirectory',
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-symlink');
+
+};
View
27 grunt/contrib-watch.js
@@ -0,0 +1,27 @@
+module.exports = function(grunt) {
+
+ grunt.config('watch', {
+ livereload: {
+ options: {
+ livereload: true,
+ },
+ files: ['app/**/*.{js,hbs}', 'build/wwwroot/*'],
+ tasks: [],
+ },
+ jshint: {
+ files: ['<%= jshint.config.src %>', '<%= jshint.app.src %>'],
+ tasks: ['jshint']
+ },
+ jade: {
+ files: ['app/pages/*.jade', 'config/**/*'],
+ tasks: ['jade:dev'],
+ },
+ stylus: {
+ files: ['<%= stylus.dev.files[0].src %>'],
+ tasks: ['stylus:dev'],
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-watch');
+
+};
View
15 grunt/gh-pages.js
@@ -0,0 +1,15 @@
+module.exports = function(grunt) {
+
+ grunt.config('gh-pages', {
+ site: {
+ options: {
+ base: 'build/wwwroot',
+ clone: 'build/gh-pages',
+ },
+ src: ['**/*'],
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-gh-pages');
+
+};

4 comments on commit 5a2980a

@mstrizzolo

Hi Ben! I have a doubt

module.exports = function(grunt) {

grunt.config('connect', {
options: {
hostname: '*',
base: 'build/wwwroot',
},
dev: {},
prod: {
options: {
keepalive: true,
},
},
});

grunt.loadNpmTasks('grunt-contrib-connect');

};

suppose you want to get the value for "base" from a config, instead of the hardcoded value 'build/wwwroot'. Is that possible?

@cowboy
Owner

You could use '<%= connect.options.base %>' per the Templates guide to retrieve the 'build/wwwroot' value from the config you posted above.

Please sign in to comment.
Something went wrong with that request. Please try again.