Module: ViteRailsLegacy::Installation
- Defined in:
- lib/vite_rails_legacy/installation.rb
Overview
Internal: Extends the base installation script from Vite Ruby to work for a typical Rails app.
Constant Summary collapse
- RAILS_TEMPLATES =
Pathname.new(File.("../../templates", __dir__))
Instance Method Summary collapse
-
#install_sample_files ⇒ Object
Override: Create a sample JS file and attempt to inject it in an HTML template.
-
#setup_app_files ⇒ Object
Override: Setup a typical apps/web Hanami app to use Vite.
Instance Method Details
#install_sample_files ⇒ Object
Override: Create a sample JS file and attempt to inject it in an HTML template.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vite_rails_legacy/installation.rb', line 19 def install_sample_files unless config.resolved_entrypoints_dir.join("application.js").exist? cp RAILS_TEMPLATES.join("entrypoints/application.js"), config.resolved_entrypoints_dir.join("application.js") end if (layout_file = root.join("app/views/layouts/application.html.erb")).exist? inject_line_before layout_file, "</head>", <<-HTML <%= vite_client_tag %> <%= vite_javascript_tag 'application' %> <!-- If using a TypeScript entrypoint file: vite_typescript_tag 'application' If using a .jsx or .tsx entrypoint, add the extension: vite_javascript_tag 'application.jsx' Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails --> HTML end end |
#setup_app_files ⇒ Object
Override: Setup a typical apps/web Hanami app to use Vite.
11 12 13 14 15 16 |
# File 'lib/vite_rails_legacy/installation.rb', line 11 def setup_app_files cp RAILS_TEMPLATES.join("config/rails-vite.json"), config.config_path if root.join("app/javascript").exist? replace_first_line config.config_path, "app/frontend", %( "sourceCodeDir": "app/javascript",) end end |