6

I've been using Middleman for a while and it always used the Rails asset pipeline for including javascript and css. So to include a javascript module called "thing.js" in the same directory, you'd do:

//= require thing

But since Middleman 4, that seems to have changed and I can't find any documentation. The closest thing I can find is this page which shows me how to run an ember.js compilation: https://middlemanapp.com/advanced/external-pipeline/

So... if I want to load javascript files in Middleman now, do I have to roll my own build system? Or am I missing something?

David Silva Smith
  • 11,498
  • 11
  • 67
  • 91
straffaren
  • 337
  • 4
  • 10

1 Answers1

7

The easy answer was to include the middleman-sprockets gem. That way things will work like they used to.

Add this to your gemfile

gem 'middleman-sprockets', '~> 4.0.0.rc.1' 

Run bundle install.

You don't need to activate anything, the middleman-sprockets extension auto-activates

David Silva Smith
  • 11,498
  • 11
  • 67
  • 91
straffaren
  • 337
  • 4
  • 10
  • Is sprockets working also for CSS? I have been fighting with this too without success! – Andrea Moro Feb 13 '16 at 18:12
  • If you can paste an example of how you used in the code it would be great. I can't figure this out and the help page for the gem isn't helpful. Also, trying to activate the gem, I got a double reference error message. – Andrea Moro Feb 13 '16 at 18:21
  • 1
    @AndreaMoro You need to include the development version of middleman-sprockets. Put this in your Gemfile: `gem 'middleman-sprockets', '~> 4.0.0.rc.1'` and run `bundle install`. You don't need to activate anything, the middleman-sprockets extension auto-activates. – straffaren Feb 15 '16 at 09:46
  • Thanks, I did it ... but I figured out only after a while all my files need to be renamed as .scss otherwise they are not pipelined. – Andrea Moro Feb 19 '16 at 16:10
  • 6
    This does now require `activate :sprockets` in your `config.rb` – stephen.hanson Dec 07 '16 at 16:16