Pergunta

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?

Foi útil?

Solução

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
    

Outras dicas

r.js can be used with node via the command line, just like middleman. I don't know how exactly you use middleman, but incorporating another command in your workflow shouldn't be a problem. You can find instructions on how to use r.js from the command line here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top