connect-preprocess

1.0.1 • Public • Published

connect-preprocess

flexible preprocessor middleware for connect / express.

Installation

npm install connect-preprocess

Basic Use

var connect = require( 'connect' );
var Preprocessor = require( 'connect-preprocess' );
var engine = require( 'some-preprocessor-engine' );
 
var server = connect.createServer();
server.use( Preprocessor({ engine: engine }));

Options

Parameter Type Description Default
accept Array File types to preprocess [ 'html' , 'css' , 'js' ]
engine Function The preprocessor engine function(str){return str}

Examples

grunt connect plugin

  • ###### Gruntfile.js

    var Preprocessor = require( 'connect-preprocess' );
     
    grunt.initConfig({
      // ...
      connect: {
        options: { port: 9000 },
        server: {
          options: {
            middleware: function ( connect , options , middlewares ) {
              middlewares.unshift( Preprocessor({ engine: grunt.config.process }));
              return middlewares;
            }
          }
        }
      },
      // ...
    });
  • ###### example.html

    <!DOCTYPE HTML>
    <html>
    <head>
        <title><%= pkg.name %></title>
        <script src="<%= pkg.main %>"></script> 
    </head>
    <body>
        <a href="<%= pkg.homepage %>">visit the homepage!</a>
    </body>
    </html>
  • ###### result

    <!DOCTYPE HTML>
    <html>
    <head>
        <title>connect-preprocess</title>
        <script src="index.js"></script> 
    </head>
    <body>
        <a href="https://github.com/elnarddogg/connect-preprocess">visit the homepage!</a>
    </body>
    </html>

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    1
    • latest
  • 1.0.0
    0
    • beta

Version History

Package Sidebar

Install

npm i connect-preprocess

Weekly Downloads

5

Version

1.0.1

License

MIT

Last publish

Collaborators

  • elnarddogg