Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Require.JS (r.js build) into the Middleman build

I work with Middleman to develop, test and build my HAML & SASS Projects.

Now I also like to work with require.js. Is there any way i could integrate the R.js build into the Middleman build?

Did you make any experience with it? How do you handle require.js in middleman?

like image 399
meo Avatar asked Feb 18 '23 09:02

meo


1 Answers

As far as just "running r.js" is concerned, it's pretty straightforward:

  1. Save r.js into the project's root.
  2. Define a custom extension (config.rb) which executes r.js after the build:

    module RequireJS
        class << self
            def registered(app)
                app.after_build do |builder|
                    exec('node r.js -o build/javascripts/app.build.js');
                end
            end
            alias :included :registered
        end
    end
    
    ::Middleman::Extensions.register(:requirejs, RequireJS)
    
  3. Activate custom extension (config.rb):

    configure :build do
        …
        activate :requirejs
    end
    
like image 170
backflip Avatar answered Feb 23 '23 06:02

backflip