Permalink
Browse files

Split Grunt config into per-task files.

  • Loading branch information...
cowboy committed Dec 2, 2013
1 parent 7581082 commit 5a2980a7818957cbaeedcd7552af9ce54e05e3fb
View
@@ -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'),

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Dec 2, 2013

Owner

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

@cowboy

cowboy Dec 2, 2013

Owner

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

});
- 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
@@ -0,0 +1,9 @@
+module.exports = function(grunt) {
+
+ grunt.config('clean', {
+ build: ['build'],
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+};
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

@gdi2290

This comment has been minimized.

Show comment
Hide comment

🍔

@kevcenteno

This comment has been minimized.

Show comment
Hide comment

👍

@mstrizzolo

This comment has been minimized.

Show comment
Hide comment
@mstrizzolo

mstrizzolo Jan 30, 2014

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?

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

This comment has been minimized.

Show comment
Hide comment
@cowboy

cowboy Jan 31, 2014

Owner

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

Owner

cowboy replied Jan 31, 2014

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.