Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active December 10, 2015 06:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save balupton/4398093 to your computer and use it in GitHub Desktop.
Save balupton/4398093 to your computer and use it in GitHub Desktop.
DocPad: Bundle your scripts with Browserify

DocPad: Bundle your scripts with Browserify

The following will bundle your script assets with browserify each time a generation write completes. The bundled file will be located at my-website/out/scripts.js if you are using all the default configuration for your paths.

Installation

  1. Install Dependencies

    npm install --save browserify safeps
  2. Add the following to your docpad configuration file

    # Write After
    # Used to bundle the editor
    writeAfter: (opts,next) ->
    	# Prepare
    	{rootPath, outPath} = @docpad.getConfig()
    
    	# Bundle the scripts the editor uses together
    	command = """
    		#{rootPath}/node_modules/.bin/browserify
    		#{outPath}/vendor/jquery.js
    		#{outPath}/scripts/script.js
    		-o #{outPath}/scripts.js
    		""".replace(/\n/g,' ')
    
    	# Execute
    	require('safeps').exec(command, {cwd:rootPath, output:true}, next)
    
    	# Chain
    	@
@jpillora
Copy link

jpillora commented Mar 8, 2013

Also need to: balUtil = require "bal-util" at the top

@digitaldesigndj
Copy link

I have created a simple docpad plugin that will do simple browserify rendering as a plugin, all you have to do is add .browserify or .b as an extension.

https://github.com/digitaldesigndj/docpad-plugin-browserify

It's working, but still a work in progress. So far I have mostly used it with https://npmjs.org/package/jquery-browserify

@digitaldesigndj
Copy link

Hmm, it seems that this gist does not work with balUtil 2.3.x, however it does work with balUtil 2.0.x

@balupton
Copy link
Author

@digitaldesigndj fixed :)

@giodamelio
Copy link

As someone who had never done much with docpad config before, it wasn't very clear that this should all be a child of events:, you might want to add that.

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