1

I have a directory structure like this:

+ src
 |
 | - modules
 | |
 | | - auth
 | | |
 | | | - auth.coffee
 | | | - auth.sass
 | | | - login.html
 | | | - logout.html
 | |
 | | - navigation
 | | |
 | | | - navigation.coffee
 | | | - navigation.sass
 | | | - navbar.html
 | | 
 | - scripts
 | |
 | | - vendor
 | | |
 | | | - underscore.js
 | | | - angular.js
 | |
 | | - app.coffee
 | | - router.coffee
 |
 | - styles
 | |
 | | - config.sass
 | | - style.sass

I want to:

  1. Watch all .coffee, .sass and .html files and do steps 2 and 3 when a file has changed

  2. Compile the .coffee and .sass files.

    For both i need to specify dependencies (or: a specific ordering).

    • Coffeescript
      • compile scripts/vendor/underscore.js
      • then scripts/vendor/angular.js
      • then scripts/*.js
      • then modules/**/*.js
    • SASS
      • compile styles/config.sass
      • then styles/style.sass
      • then modules/**/*.sass
  3. Collect all .js, .css and .html files and organize them for the public folder.

This is the desired output

+ public
 |
 | - partials
 | |
 | | - auth
 | | |
 | | | - login.html
 | | | - logout.html
 | |
 | | - navigation
 | | |
 | | | - navbar.html
 | | 
 | - scripts
 | |
 | | - app.js
 |
 | - styles
 | |
 | | - app.css

I tried many tools, but couldn't get the desired result. For example Flour for the Coffeescript had problems with wildcards in compile methods.

I think the best thing would be a Cakefile that does everything for me. How can i accomplish this?

asked Mar 14, 2014 at 15:16

1 Answer 1

1

First, why compile underscore or angular? Just link to the minified version on a CDN. You might be able to get better performance by packing those together with your app js, I don't have a solid yes/no answer on this, you'll have to research.

I think you should be able to accomplish this with grunt. My config isn't exactly what you want but:

 # Project configuration.
 grunt.initConfig
 watch:
 coffee:
 files: ['app/assets/src/coffee/**/*.coffee', 'app/assets/src/coffee/*.coffee', 'test/*.coffee', '!**/screencaps/**', 'app/webserver.coffee']
 tasks: ['coffee:dev', 'replace', 'mochaTest']
 grunt.loadNpmTasks("grunt-contrib-coffee")
 grunt.loadNpmTasks('grunt-contrib-watch')

Etc. Grunt uses glob for file pattern matching. For what you want to do I'd set up a chain of watch commands:

  1. Watch for a change in src/modules/*.coffee
  2. Compile (and optionally uglify) all coffee to js, move to public/scripts.
  3. Do the same for SASS files.
answered Mar 14, 2014 at 19:25
Sign up to request clarification or add additional context in comments.

1 Comment

you are completely right about not compiling js files. it should have been: compile coffescripts and concat them with all js files

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.