Skip to content

Instantly share code, notes, and snippets.

@ro-ka
Last active December 15, 2015 16:59
Show Gist options
  • Select an option

  • Save ro-ka/5293002 to your computer and use it in GitHub Desktop.

Select an option

Save ro-ka/5293002 to your computer and use it in GitHub Desktop.
Upgrade to yeoman 1.0 and grunt 0.4 with jade templating

Upgrade to yeoman 1.0 and grunt 0.4 with jade templating

First, remove the old versions and install the new ones:

npm uninstall -g yeoman grunt
npm install -g yo grunt-cli bower

Add this to the devDepencies in your package.json:

"grunt": "~0.4.0",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-concat": "~0.1.2",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-compass": "~0.1.2",
"grunt-contrib-cssmin": "~0.4.1",
"grunt-contrib-connect": "0.1.2",
"grunt-contrib-clean": "0.4.0",
"grunt-contrib-htmlmin": "0.1.1",
"grunt-contrib-imagemin": "0.1.2",
"grunt-contrib-livereload": "0.1.1",
"grunt-bower-hooks": "~0.2.0",
"grunt-usemin": "~0.1.9",
"grunt-regarde": "~0.1.1",
"grunt-mocha": "~0.2.2",
"grunt-open": "~0.2.0",
"grunt-jade": "~0.4.0",
"matchdep": "~0.1.1"

Install the modules:

npm install -dev

And finally, replace the Gruntfile.js with the one attached here.

// Generated on 2013-04-02 using generator-webapp 0.1.5
'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var yeomanConfig = {
app: 'app',
dist: 'dist'
};
grunt.initConfig({
yeoman: yeomanConfig,
watch: {
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass']
},
jade: {
files: ['<%= yeoman.app %>/**/*.jade'],
tasks: ['jade']
},
livereload: {
files: [
'<%= yeoman.app %>/*.html',
'{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,webp}'
],
tasks: ['livereload']
}
},
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost'
},
livereload: {
options: {
middleware: function (connect) {
return [
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app')
];
}
}
},
test: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, '.tmp'),
mountFolder(connect, 'test')
];
}
}
},
dist: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, 'dist')
];
}
}
}
},
open: {
server: {
path: 'http://localhost:<%= connect.options.port %>'
}
},
clean: {
dist: ['.tmp', '<%= yeoman.dist %>/*'],
server: '.tmp'
},
mocha: {
all: {
options: {
run: true,
urls: ['http://localhost:<%= connect.options.port %>/index.html']
}
}
},
jade: {
all: {
files: {
'<%= yeoman.app %>/': ['<%= yeoman.app %>/*.jade']
},
options: {
pretty: true,
client: false
}
}
},
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
imagesDir: '<%= yeoman.app %>/images',
javascriptsDir: '<%= yeoman.app %>/scripts',
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: 'app/components',
relativeAssets: true
},
dist: {},
server: {
options: {
debugInfo: true
}
}
},
// not used since Uglify task does concat,
// but still available if needed
/*concat: {
dist: {}
},*/
uglify: {
dist: {
files: {
'<%= yeoman.dist %>/scripts/main.js': [
'<%= yeoman.app %>/scripts/{,*/}*.js'
]
}
}
},
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
cssmin: {
dist: {
files: {
'<%= yeoman.dist %>/styles/main.css': [
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/styles/{,*/}*.css'
]
}
}
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: '*.html',
dest: '<%= yeoman.dist %>'
}]
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,txt}',
'.htaccess'
]
}]
}
}
});
grunt.renameTask('regarde', 'watch');
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'jade',
'compass:server',
'livereload-start',
'connect:livereload',
'open',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'jade',
'compass',
'connect:test',
'mocha'
]);
grunt.registerTask('build', [
'clean:dist',
'jade',
'compass:dist',
'useminPrepare',
'imagemin',
'htmlmin',
'concat',
'cssmin',
'uglify',
'copy',
'usemin'
]);
grunt.registerTask('default', [
'test',
'build'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment