Exporting the Static Site
Building the site with
Finally, when you are ready to deliver static code or, in the case of "blog
mode", host a static blog, you will need to build the site. Using the
command-line, from the project folder, run
$ cd my_project $ bundle exec middleman build
This will create a static file for each file located in your
Template files will be compiled, static files will be copied and any enabled
build-time features (such as compression) will be executed. Middleman will
automatically clean out files from the build directory for you that are left
over from earlier builds but would no longer be produced.
To speed up the build time, you can expose the variable
$ cd my_project $ NO_CONTRACTS=true bundle exec middleman build
Contracts are used to add type signatures to certain methods, and Middleman uses them to override and clear the gems' classes so no type checking is performed - they're only used internally. For a more in depth description, you can watch a video explaining this behavior.
Deploying the site
After building the site you have everything you need within the
build-directory. There are nearly limitless ways to deploy a static build. So
we present our very own solution for this here. Feel free to search the web or
look at our extension directory for more alternatives to deploy Middleman. If
you are an author of a deployment tool suitable to deploy Middleman, please
open a pull request to the directory.
A very handy tool to deploy a build is
middleman-deploy. It can deploy a
site via rsync, FTP, SFTP, or Git.
$ middleman build [--clean] $ middleman deploy [--build-before]
Production Asset Hashing & CDN Configuration
A common setup for production is to hash your assets and serve them through a CDN. You can do this easily with Middleman: