jasonkarns
7/24/2013 - 7:08 PM

Support arbitrary static files in Lineman with the grunt-contrib-copy task

Support arbitrary static files in Lineman with the grunt-contrib-copy task

Support arbitrary static files in Lineman with the grunt-contrib-copy task

  1. add grunt-contrib-copy task to package.json package.json line 2
  2. configure lineman to load the task via npm config/application.coffee line 4
  3. configure lineman to run the copy task as part of its run/build process config/application.coffee lines 9-11
  4. configure the copy task itself config/application.coffee lines 14-18

With this configuration, any file or directory (recursively) in static/ will be copied over as a static asset. (directory structure is preserved.) For example, given:

static/
  favicon.ico
  js/
    html5shim.js

Then lineman build (with latest lineman, and default setup) will create:

dist/
  css/
    app.css
  favicon.ico
  index.html
  js/
    app.js
    html5shim.js

Warning: If there are any name conflicts between files in 'static' and the normal lineman build assets, the static files will overwrite the others (since the copy task is run last).

"dependencies": {
  "grunt-contrib-copy": "~0.4.1"
}
module.exports = require(process.env['LINEMAN_MAIN']).config.extend "application",

  # tell lineman to load the grunt-contrib-copy task via npm
  loadNpmTasks: 'grunt-contrib-copy'

  # tell lineman to run the copy tasks as part of its build process
  #   run 'dev' target for both run and build phases
  #   run 'dist' target during build phase
  appendTasks:
    common: "copy:dev"
    dist: "copy:dist"

  # configure the copy task
  copy:
    dev:
      files: [ expand: true, cwd: 'static', src: '**', dest: 'generated' ]
    dist:
      files: [ expand: true, cwd: 'static', src: '**', dest: 'dist' ]