Skip to content

Instantly share code, notes, and snippets.

@hiroki-uchida
Last active October 25, 2017 13:57
Show Gist options
  • Save hiroki-uchida/6afce9ef1a65f5d3aa3143486f39cd86 to your computer and use it in GitHub Desktop.
Save hiroki-uchida/6afce9ef1a65f5d3aa3143486f39cd86 to your computer and use it in GitHub Desktop.
middlemanでhtmlを圧縮した状態でbuildする方法

middlemanでhtmlを圧縮した状態でbuildする方法

  1. Gemfilegem 'middleman-minify-html' を追加
  2. $ bundle install を実行
  3. config.rbconfigure :build のブロックに activate :minify_html を追加

あとは通常通り $ bundle exec middleman build を実行するだけで minify された HTMLbuild されるようになる。

参考

middleman/middleman-minify-html: A HTML whitespace minifier for Middleman https://github.com/middleman/middleman-minify-html

# ---
# File: config.rb
# ---
configure :build do
# この行を追加
activate :minify_html
# 細かい設定をする場合はこのようにブロックすることで可能
#
# 参照: https://github.com/middleman/middleman-minify-html
activate :minify_html do |html|
html.remove_multi_spaces = true # Remove multiple spaces
html.remove_comments = true # Remove comments
html.remove_intertag_spaces = true # Remove inter-tag spaces
html.remove_quotes = false # Remove quotes
html.simple_doctype = false # Use simple doctype
html.remove_script_attributes = false # Remove script attributes
html.remove_style_attributes = false # Remove style attributes
html.remove_link_attributes = false # Remove link attributes
html.remove_form_attributes = false # Remove form attributes
html.remove_input_attributes = false # Remove input attributes
html.remove_javascript_protocol = true # Remove JS protocol
html.remove_http_protocol = false # Remove HTTP protocol
html.remove_https_protocol = false # Remove HTTPS protocol
html.preserve_line_breaks = false # Preserve line breaks
html.simple_boolean_attributes = true # Use simple boolean attributes
html.preserve_patterns = nil # Patterns to preserve
end
end
# ---
# File: Gemfile
# ---
# この行を追加
gem 'middleman-minify-html'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment