Skip to content

Instantly share code, notes, and snippets.

@airtonix
Last active January 3, 2016 01:29
Show Gist options
  • Save airtonix/8389934 to your computer and use it in GitHub Desktop.
Save airtonix/8389934 to your computer and use it in GitHub Desktop.
Assemble GruntFile for generating static website to be hosted on github pages.
Processing as HTML - ./_gh_pages/about/index.html
Update the HTML to reference our concat/min/revved script files
Update the HTML with the new css filenames
Update the HTML with the new img filenames
Update the HTML with data-main tags
Update the HTML with data-* tags
Update the HTML with background imgs, case there is some inline style
Update the HTML with anchors images
Update the HTML with reference in input
Processing as HTML - ./_gh_pages/index.html
Update the HTML to reference our concat/min/revved script files
<script src="/assets/js/vendor-ie9.js" changed to <script src="/assets/js/5bde7f6d.vendor-ie9.js"
<script src="/assets/js/vendor.js" changed to <script src="/assets/js/f715a94c.vendor.js"
<script src="/assets/js/main.js" changed to <script src="/assets/js/4e4fdbad.main.js"
Update the HTML with the new css filenames
<link rel="stylesheet" href="/assets/css/vendor.css" changed to <link rel="stylesheet" href="/assets/css/b59e1632.vendor.css"
<link rel="stylesheet" href="/assets/css/print.css" changed to <link rel="stylesheet" href="/assets/css/34072614.print.css"
<link rel="stylesheet" href="/assets/css/screen.css" changed to <link rel="stylesheet" href="/assets/css/dcd0f50c.screen.css"
Update the HTML with the new img filenames
Update the HTML with data-main tags
Update the HTML with data-* tags
Update the HTML with background imgs, case there is some inline style
Update the HTML with anchors images
Update the HTML with reference in input
module.exports = function (grunt) {
var matchdep = require('matchdep');
matchdep.filterDev('grunt-*').forEach(grunt.loadNpmTasks)
matchdep.filterDev('assemble-*').forEach(grunt.loadNpmTasks)
matchdep.filterDev('assemble').forEach(grunt.loadNpmTasks)
grunt.util._.mixin({
read: function(src) {
grunt.file.read(require('path').join('src/data', src));
}
});
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
site: grunt.file.readYAML('config.yml'),
assemble: {
options: {
engine: 'swig',
site: '<%= site %>',
plugins: [
'assemble-contrib-anchors',
'assemble-contrib-toc'
],
assets: 'assets',
helpers: ['src/extensions/**/*.js', ],
layoutdir: 'src/templates/',
layoutext: '.html'
},
site: {
files:[{
expand: true,
cwd: 'src/data/pages',
src: [
'*.{md,markdown,yml}',
'**/*.{md,markdown,yml}'
],
dest: '<%= site.dest %>'
}]
}
},
useminPrepare: {
options: {
dest: "<%= site.dest %>",
root: "src"
},
html: "<%= site.dest %>/**/*.html",
css: "<%= site.dest %>/**/*.css"
},
less:{
options: {
paths: [
'src/assets/vendor/',
'src/assets/less/'
]
},
vendor: {
files: {
"src/assets/vendor/ui-kit/css/main.css": [
"src/assets/vendor/ui-kit/less/main.less"
]
}
},
site: {
files: {
"src/assets/css/screen.css": [
"src/assets/less/screen.less"
],
"src/assets/css/print.css": [
"src/assets/less/print.less"
]
}
}
},
copy: {
dist: {
files: [{
expand: true,
dest: '<%= site.dest %>/assets/',
src: "src/assets/**/*"
}]
}
},
rev: {
options: {
algorithm: 'md5',
length: 8
},
assets: {
files: {
src: [
'<%= site.dest %>/assets/js/{,*/}*.js',
'<%= site.dest %>/assets/css/{,*/}*.css',
'<%= site.dest %>/assets/img/{,*/}*.{png,jpg,jpeg,gif,webp}',
'<%= site.dest %>/assets/font/{,*/}*.*'
]
}
}
},
usemin: {
html: "<%= site.dest %>/{,*/}*.html",
css: "<%= site.dest %>/{,*/}*.css",
options: {
assetDirs: [
'<%= site.dest %>/',
'<%= site.dest %>/assets/'
]
}
},
watch: {
pages: {
files: [
'src/data/**/*',
'src/assets/**/*',
'src/templates/**/*',
'GruntFile.js'
],
tasks: ['build', 'watch']
}
},
connect: {
dist: {
options: {
port: 5455,
hostname: '0.0.0.0',
base: '<%= site.dest %>',
livereload: false
}
}
},
clean: {
dist: [
'<%= site.dest %>',
],
temp: [
'.tmp',
'.grunt'
]
},
});
grunt.registerTask('build', [
'clean',
'assemble',
'less',
'useminPrepare',
// 'imagemin',
'concat',
'cssmin',
// 'htmlmin',
'uglify',
'rev',
'usemin'
]);
grunt.registerTask('server', [
'build',
'connect',
'clean:temp',
'watch'
]);
grunt.registerTask('default', 'server');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment