Skip to content

Instantly share code, notes, and snippets.

@garth
Created November 22, 2012 19:49
Show Gist options
  • Save garth/4132681 to your computer and use it in GitHub Desktop.
Save garth/4132681 to your computer and use it in GitHub Desktop.
Use snockets to package javascript files for debug output (with //@ sourceURL)
#entry point for js/coffee dependency tree
rootfile = 'root.js'
#get the file names and content
files = snockets.getCompiledChain rootfile, { async: false }
#package each file in eval with trailing //@ sourceURL
scripts = []
for file in files
script = file.js.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/'/g, '\\\'')
name = path.relative(path.dirname(@filename), file.filename)
scripts.push "// #{name}\neval('#{script}\\n//@ sourceURL=#{name}')\n"
# join scripts into single package ready to be sent to the client
jsPackage = scripts.join('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment