Skip to content

How can a Rails engine be adapted to support both Propshaft and Sprockets based installations  #219

Open
@westonganger

Description

@westonganger

With the release of Rails 8 and new apps having Propshaft instead of Sprockets, How are Rails engines being made to work for both styles? For example many gems contains a Web UI which is a Rails engine.

So far whats been suggested is using /public for assets and using CDN script/link tags for external assets. This is mostly an approach I have already been using.

Im hoping there should be a better story than this.

So far this is the only sprockets configuration that may be relevant to this conversation. Just including it here for completeness.

  initializer "foo_app.assets.precompile" do |app|
    app.config.assets.precompile << "foo_app_manifest.js" ### manifest file required
    app.config.assets.precompile << "foo_app/favicon.ico"

    ### Automatically precompile assets in specified folders
    ["app/assets/images/"].each do |folder|
      dir = app.root.join(folder)

      if Dir.exist?(dir)
        Dir.glob(File.join(dir, "**/*")).each do |f|
          asset_name = f.to_s
            .split(folder).last # Remove fullpath
            .sub(/^\/*/, '') ### Remove leading '/'

          app.config.assets.precompile << asset_name
        end
      end
    end
  end

Also posted this question to reddit: https://www.reddit.com/r/rails/comments/1gtin65/how_can_a_rails_engine_be_adapted_to_support_both/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions