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
    	@
@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