javascriptsprocketsmiddlemanmiddleman-4

How to include javascript in middleman 4?


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?


Solution

  • 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