nikushi / minipack

Minipack, a gem for minimalists, which can integrates Rails with webpack. It is an alternative to Webpacker.
MIT License
115 stars 22 forks source link

Improve configuration system by introducing 2-levels capability #10

Closed nikushi closed 5 years ago

nikushi commented 5 years ago

I intend to introduce a RSpec module to add pre-compilation feature in test mode. To do this, Configuration has to be more configurable per site. For example, base_path, which is a parameter will be introduced later, to address a base directory of each frontend system, has to become configurable per site, if a Rails project has more than one site.

# Note: base_path has not introduced yet.
WebpackManifest::Rails.configuration do |c|
  # The settings called within the root configuration scope are enabled in all sites,
  # which means enabled in :shop and :admin.
  c.cache = !Rails.env.development?

  c.add :shop do |co|
    # These are enabled only in :shop
    co.manifest = Rails.root.join('public', 'assets', 'manifest-shop.json')
    co.base_path = Rails.root.join('frontend', 'shop')
  end

  c.add :admin do |co|
    # These are enabled only in :admin
    co.manifest = Rails.root.join('public', 'assets', 'manifest-admin.json')
    co.base_path = Rails.root.join('frontend', 'admin')
  end

This pull request improves Configuration class in advance, with backward compatible.