Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is it possible to add another dev directory inside /app for react-rails? #1343

Answered by ritikm31
bubuluxWork asked this question in Q&A
Discussion options

I am migrating our codebase to Typescript and want new code to be written in a new directory: app/typescript. Note: I don't need any SSR, typical SPA behavior is sufficient. It would be nice to be able to configure bundle splitting (like with app/javascript/packs)...

I am very new to the entire RoR ecosystem and thus it's tough for me to pinpoint where I want to look for making changes.

Would anyone be able to help me out here? Is what I want even possible?

In any case: Thx for all the resources you guys invest in making RoR development approachable for people with vastly different backgrounds (React etc.), really appreciated :)

Best, Sam

You must be logged in to vote

Yes, it’s possible to add another dev directory inside the /app folder in a React-Rails application, but it depends on your specific use case. Here’s a general overview of how you might approach it:

Creating the Directory: You can add a new directory under /app by simply creating an app/dev folder. This is useful for organizing files or components specific to your development environment, like development-only React components, utilities, or test helpers.

Configuring Webpack (if you're using it): If the dev directory contains JavaScript files or React components, you may need to update your Webpack configuration (if custom-configured) to ensure it compiles assets from this new directory.

R...

Replies: 1 comment 1 reply

Comment options

Yes, it’s possible to add another dev directory inside the /app folder in a React-Rails application, but it depends on your specific use case. Here’s a general overview of how you might approach it:

Creating the Directory: You can add a new directory under /app by simply creating an app/dev folder. This is useful for organizing files or components specific to your development environment, like development-only React components, utilities, or test helpers.

Configuring Webpack (if you're using it): If the dev directory contains JavaScript files or React components, you may need to update your Webpack configuration (if custom-configured) to ensure it compiles assets from this new directory.

Rails Autoload Paths: By default, Rails autoloads certain directories within /app like /app/models, /app/controllers, and /app/helpers. If you need Rails to load Ruby files from the dev directory automatically, you can configure it by adding this line to your config/application.rb:

ruby
Copy code
config.autoload_paths += %W(#{config.root}/app/dev)
Environment-Specific Code: If you only want the code in app/dev to be available in development, you can wrap it with Rails.env.development? checks.

React-Rails Integration: If you're using React components in this dev directory and you want Rails to recognize them, make sure the paths are accessible. The react-rails gem will load components based on what is available to the asset pipeline or Webpack configuration.

You must be logged in to vote
1 reply
Comment options

Sorry, that was a while back, just saw the reply. Thx for taking the time to explain this, I eventually stuck with the defaults. Thx anyhow

Answer selected by Judahmeek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /