Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeitwerk should ignore preview files when previews are disabled #25

Open
palkan opened this issue Sep 28, 2022 Discussed in #24 · 0 comments
Open

Zeitwerk should ignore preview files when previews are disabled #25

palkan opened this issue Sep 28, 2022 Discussed in #24 · 0 comments
Labels
enhancement New feature or request

Comments

@palkan
Copy link
Owner

palkan commented Sep 28, 2022

Discussed in #24

Originally posted by dhnaranjo September 23, 2022
Hello! So I'm trying to do the following:

  • keeping Preview files in app/components/component_name
  • building previewed objects using FactoryBot and Faker
  • including FactoryBot::Syntax::Methods in ApplicationViewComponentPreview so I can call build instead of FactoryBot.build
  • excluding FactoryBot from my Production environment

The result is that when my app directory is eager loaded in Production it gets all upset that FactoryBot::Syntax::Methods doesn't exist. To fix this I put together an initializer looks a lil something like this:

# config/initializers/zeitwerk_view_component_previews.rb

unless Rails.env.development? || Rails.env.test?
  Rails.autoloaders.each do |autoloader|
    autoloader.ignore(
      Rails.application.config.view_component.preview_paths.flat_map { Pathname(_1).glob("**/*preview.rb") }
    )
  end
end

I think this is a pretty good idea to include something like this here so other folks can avoid this particular dumb trap.

@palkan palkan added the enhancement New feature or request label Sep 28, 2022
@palkan palkan changed the title Zeitwerk should ignore Preview files in non-Dev/Test env(?) Zeitwerk should ignore preview files when previews are disabled Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant