SpontaneousCMS/spontaneous

View on GitHub
lib/spontaneous/generators/site/config/initializers/assets.rb.tt

Summary

Maintainability
Test Coverage
# Configure our asset handling
#
# Add any commands that should be run as part of the development cycle below,
# i.e. any asset pipeline watchers or helpers
# This should be a hash of "command name" => proc where the proc takes one
# argument which is the directory to build to and returns a string which is the
# shell command to run.

# Important: your command is not run through a shell, so:
#
# - all paths should be absolute
# - avoid any variable interpolation

# A convenience method to provide a default webpack command
def webpack_base(output_dir)
  yarn_bin = `yarn bin`.chomp
  webpack_config = ::File.expand_path('./webpack.config.js')

  "#{yarn_bin}/webpack --config '#{webpack_config}' --progress --color --output-path='#{output_dir}'"
end

Site.development_watchers = {
  # webpack: proc { |output_dir|
  #   "#{webpack_base(output_dir)} --watch"
  # }
}

# During deployment your assets will be pre-compiled and uploaded to the remote
# server so that in there are no asset-compilation steps run on the production
# server.

# Add any asset compilation commands here.

# Note: the output_dir value will be some temp dir during this stage, so it's
# **essential** that your compilation process respects this value.

Site.deploy_asset_compilation = {
  webpack: proc { |output_dir|
    # -p means minify
    "#{webpack_base(output_dir)} -p"
  }
}

# Optionally override the proc called during asset fingerprinting

# Site.deploy_asset_fingerprint = proc { |base, md5, ext|
#   "#{base}-#{md5}#{ext}"
# }