Create a gist now

Instantly share code, notes, and snippets.

@balupton /README.md
Last active Dec 10, 2015

What would you like to do?
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 commented Mar 8, 2013

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

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

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

Owner

@digitaldesigndj fixed :)

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