Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 963 Bytes

README.md

File metadata and controls

57 lines (42 loc) · 963 Bytes

Simpacker Rails Engines example

Settings for engine

my_engine/config/simpacker.yml

default: &default
  manifest_path: public/packs/my_engine/manifest.json

development:
  <<: *default
  cache_manifest: false

test:
  <<: *default
  cache_manifest: false

production:
  <<: *default
  cache_manifest: true

my_engine/lib/my_engine.rb

require "my_engine/engine"

module MyEngine
  ROOT_PATH = Pathname.new(File.join(__dir__, ".."))

  def self.simpacker_context
    @simpacker_context ||= Simpacker::Context.new(root_path: ROOT_PATH)
  end
end

my_engine/app/helpers/my_engine/application_helper.rb

module MyEngine
  module ApplicationHelper
    include Simpacker::Helper

    def simpacker_context
      MyEngine.simpacker_context
    end
  end
end

Serving

# config/application.rb
config.middleware.use(Rack::Static, urls: ["/packs/my_engine"], root: MyEngine::Engine.root.join("public"))