Skip to content

Instantly share code, notes, and snippets.

@crueber
Last active August 29, 2015 14:16
Show Gist options
  • Save crueber/2580a215a5af03259a4e to your computer and use it in GitHub Desktop.
Save crueber/2580a215a5af03259a4e to your computer and use it in GitHub Desktop.
connect-assets production setup for heroku
prodAssetHelpers = require("./middleware/prod_asset_helpers")
if app.get('env') == 'production'
app.use express.static(path.join(__dirname, "/../public"), maxAge: constant.one_week)
prodAssetHelpers(app, path.join(__dirname, "/../public"))
else
app.use express.static(path.join(__dirname, "/../public"), maxAge: constant.one_second)
app.use connectAssets(paths: [ "public/css", "public/js" ], helperContext: app.locals, build: false)
{
"scripts": {
"install": "./node_modules/.bin/connect-assets -i public/js public/css -c styles* application.js -o public/assets -gz"
}
}
module.exports = (app, asset_path) ->
manifest = require asset_path+"/assets/manifest.json"
app.locals.js = (file) -> '<script src="/assets/'+manifest.assets[file+'.js']+'"></script>'
app.locals.css = (file) -> '<link rel="stylesheet" href="/assets/'+manifest.assets[file+'.css']+'"/>'
@crueber
Copy link
Author

crueber commented Mar 7, 2015

...because I got tired of a kludged together setup. Keep in mind that the install script has to be customized to your environment. I never got wildcards to work for my less files for some reason, without putting it at the end of the filename. If anyone has any thoughts, I'd welcome them.

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