Skip to content

Instantly share code, notes, and snippets.

Last active August 30, 2016 15:34
What would you like to do?
An example of how to use [node-ssi]( in a custom Grunt task to inline all your apache includes.

Flatten SSI Includes

An example of how to use node-ssi in a custom Grunt task to inline all your apache includes.


Download the gist.

From the root of the project, run the following steps in your terminal:

  1. Install the dependencies.

     $ npm install
  2. Run grunt.

     $ grunt
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
module.exports = function( grunt ) {
pkg: grunt.file.readJSON( 'package.json' ),
buildPath: '../<%= %>-build/',
clean: {
options: {
force: true
dist: [ '<%= buildPath %>' ]
copy: {
dist: {
files: [
src: [
dest: '<%= buildPath %>'
ssi: {
options: {
input: '<%= buildPath %>',
output: '<%= buildPath %>',
matcher: '**/*.html'
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.registerTask('ssi', 'Flatten SSI includes in your HTML files.', function() {
var ssi = require( 'ssi' )
, opts = this.options()
, files = new ssi( opts.input, opts.output, opts.matcher )
grunt.registerTask( 'default', [
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Flatten SSI</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<h1>Flatten SSI</h1>
<!--#include file="" -->
"name": "Flatten-SSI",
"version": "0.0.1",
"author": "Ryan Fitzer",
"dependencies": {
"grunt": "~0.4.1",
"grunt-contrib-clean": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"ssi": "~0.1.2"
Copy link

Thank you @ryanfitzer!
This was really helpful! Sometimes the people developing the packages are too spartan in their explanations. Your gist truly saved my day. ;-)
Keep on rocking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment