0.01
No release in over 3 years
Low commit activity in last 3 years
a teeny engine that turns your rails 5 application into a lean, mean, static site building machine.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.3.0, ~> 2.3
>= 5.0.30, ~> 5.0
>= 2.0.1, ~> 2.0
>= 5, ~> 5
>= 1.4.5, ~> 1.4
 Project Readme

RailsBuild

A very small, very simple, very fast, and bullet proof static site generator built as a Rails 5 engine.

How It Works

RailsBuild bundles all your assets, public directory, and configured urls into a static site suitable for deployment to Netlify, Amazon S3, or your favorite static website hosting solution. It does this by:

  • Booting your application in production mode
  • Precompiling all assets
  • Including every static resource in ./public/
  • GET'ing every configured url via super fast parallel downloading

RailsBuild let's you leverage the entire Rails' ecosystem for your static sites and requires learning practically no new techniques to make super fast building static websites.

Configuration

Configuration is quite simple, typically it will be much less than comparable static site generators. You need to drop a ./config/rails_build.rb looking something like this into your app:

  RailsBuild.configure do |rails_build|

    urls = rails_build.urls

    urls << "/"

    urls << "/about/"

    urls << "/contact/"

 
    Post.each do |post|
      urls << blog_path(post) 
    end

  end

That's it: simply enumerate the urls - anything additional to your assets and ./public/ directory - that you want to include in your build.

On Trailing Slashes

Most static hosting solutions support Apache style directory indexing and will be better behaved with urls that look like

  http://my.site.com/blog/

vs.

  http://my.site.com/blog

RailsBuild tries to help you do this with a little bit of Rails' config that is turned on by default but which can be turned off via

  RailsBuild.configure do |rails_build|

    rails_build.trailing_slash false  # the default is 'true'

  end

The only real impact will be felt if you are using relative urls in your site like './about' vs. '../about'

Optimization and Notes

RailsBuild is fast. Very fast. DOJO4 has seen optimized Middleman builds of > 30 minutes dropped to 60 seconds by simply making basic use of Rails' built-in caching facilites.

You app has to run in production mode to build! Don't forget to setup secrets, or anything else generally required in production mode.

When trying to squeeze out performance just remember that RailsBuild runs in production mode and, therefore, making a build go fast follows the exact same rules as making anything other Rails' application fast. The first place to reach is typically fragment caching of partials used in your app.

Finally, don't forget about ./config/initializers/assets.rb - RailsBuild doesn't do anything special to the asset pipeline and only those assets normally built when

  ~> rake assets:precompile

is run will be included in the build.

Installation

Add this line to your application's Gemfile:

  gem 'rails_build'

And then execute:

$ bundle

$ bundle binstubs rails_build

Building Your Site

After installation and configuration simply run

  ~> ./bin/rails_build


# or, if you prefer, simply

  ~> rails build

Netlify

We love Netlify at DOJO4. RailsBuild works with netlify out of the box and simply requires

  build_command : ./bin/rails_build

  build_directory: build

to be configured as the build command and directory respectively.

License

The gem is available as open source under the terms of the MIT License.