1

I'm building a JS widget using Coffeescript. I'm playing some tricks to get my CSS/SCSS and HTML/HAML templates into the JS widget upon compilation:

# widget.js.coffee.erb
class Widget
  constructor: (options) ->
  @template = <%= Haml::Engine.new(
    File.read(
    File.expand_path("../../templates/widget.html.haml", __FILE__))).
    render.to_json %>

  @css = <%= Sass.compile_file(
    File.expand_path("../../stylesheets/widget.css.scss", __FILE__)).
    to_json  %>

The problem is that when I change the HTML or CSS, Rails is not recompiling the Coffeescript in development because the coffeescript file is not changing. I need to make silly whitespace changes to force it to recompile things. This is getting annoying :-)

Any ideas on how to force the asset pipeline to compile certain files on every request?

1 Answer 1

3

Got it. Sprockets has a depend_on directive. Adding the following lines to my widget.js.coffee.erb solved it:

# coffee.js.coffee.erb
#= depend_on '../templates/widget.html.haml'
#= depend_on '../stylesheets/widget.css.scss'

class Widget
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.