Skip to content

Instantly share code, notes, and snippets.

@ryanfitzer
Last active Aug 30, 2016
Embed
What would you like to do?
An example of how to use [node-ssi](https://npmjs.org/package/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.

Instructions

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 ) {
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
buildPath: '../<%= pkg.name %>-build/',
clean: {
options: {
force: true
},
dist: [ '<%= buildPath %>' ]
},
copy: {
dist: {
files: [
{
src: [
'**',
'!**/node_modules/**'
],
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 )
;
files.compile();
});
grunt.registerTask( 'default', [
'clean',
'copy',
'ssi'
]);
};
<!DOCTYPE html>
<html lang="en">
<head>
<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">
</head>
<body>
<h1>Flatten SSI</h1>
<!--#include file="content.inc" -->
</body>
</html>
{
"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"
}
}
@aboutandre
Copy link

aboutandre commented Aug 30, 2016

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