Correct way to build assets?

I have a bunch of CSS files and a bunch of JS files. For development, I’m requiring them all in an all.css and all.js and adding <%= stylesheet_link_tag 'all' %> and <%= javascript_link_tag 'all' %> in my layout.

When I build, I am seeing that build/javascripts/ and build/stylesheets have not only concatenated and minified all the files in all.js and all.css, but it has built all the other files individually as well! That seems fine because build/index.html is only including the all files, but I am wondering if this is the correct way to build?

My config.rb looks like this:

set :css_dir, 'stylesheets'

set :js_dir, 'javascripts'

set :images_dir, 'images'

# Build-specific configuration
configure :build do
  # For example, change the Compass output style for deployment
  activate :minify_css

  # Minify Javascript on build
  activate :minify_javascript

  # Enable cache buster
  activate :asset_hash

  # Use relative URLs
  activate :relative_assets
end

Hi mehulkar,

Yes, that’s the expected behaviour of Middleman. Some people include different stylesheets and JavaScripts in different pages. The fact that there might be a stylesheet that includes all of them shouldn’t get in the way of that.

If you want to omit those assets from the build, you can either use Middleman’s ignore directive or rename those assets so that they start with an underscore (e.g. source/stylesheets/_typography.scss).

1 Like