### Install Dependencies Source: https://github.com/elmassimo/vite_ruby/blob/main/vite_plugin_legacy/README.md After adding the gem to your Gemfile, run bundle install to install the necessary dependencies. ```bash bundle install ``` -------------------------------- ### Install Vite Ruby Source: https://github.com/elmassimo/vite_ruby/blob/main/README.md After adding the gem to your Gemfile, run bundle install and then execute the vite install command to generate configuration files and a sample setup. ```bash bundle install bundle exec vite install ``` -------------------------------- ### Install Vite Ruby Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/index.md Run the installation command to set up Vite Ruby. This command adds necessary executables, installs Vite and its plugins, creates configuration files, and injects tag helpers into your layout. ```bash bundle exec vite install ``` -------------------------------- ### Run Development Server Source: https://github.com/elmassimo/vite_ruby/blob/main/examples/hanami_bookshelf/README.md Start the Hanami development server. ```bash % bundle exec hanami server ``` -------------------------------- ### Install Dependencies Source: https://github.com/elmassimo/vite_ruby/blob/main/CONTRIBUTING.md Run these commands to install Ruby and pnpm dependencies for the development environment. ```shell bundle install ``` ```shell pnpm install ``` -------------------------------- ### Avoid Double Dependency Installation Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/troubleshooting.md Example of a deployment script that could lead to double dependency installation. Ensure your deployment process avoids pruning development dependencies. ```bash npm ci # later NPM_CONFIG_INCLUDE="dev" npm ci ``` -------------------------------- ### Install vite-plugin-rails Source: https://github.com/elmassimo/vite_ruby/blob/main/vite-plugin-rails/README.md Install the plugin using npm or yarn. ```bash npm i vite-plugin-rails # yarn add vite-plugin-rails ``` -------------------------------- ### Start Vite Development Server Source: https://github.com/elmassimo/vite_ruby/blob/main/README.md To start the Vite development server, run the bin/vite dev command. This command is essential for the development workflow. ```bash bin/vite dev ``` -------------------------------- ### Run Development Console Source: https://github.com/elmassimo/vite_ruby/blob/main/examples/hanami_bookshelf/README.md Start the Hanami development console for interactive use. ```bash % bundle exec hanami console ``` -------------------------------- ### Install vite-plugin-ruby Source: https://github.com/elmassimo/vite_ruby/blob/main/vite-plugin-ruby/README.md Install the plugin using npm or yarn. This is typically handled by framework-specific gems like vite_rails. ```bash npm i vite-plugin-ruby # yarn add vite-plugin-ruby ``` -------------------------------- ### Start Rails Server Source: https://github.com/elmassimo/vite_ruby/blob/main/vite-plugin-ruby/src/dev-server-index.html Run this command in your terminal to start the Rails server, which integrates with the Vite development server for HMR. ```bash bin/rails s ``` -------------------------------- ### Directory Structure Example Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/development.md Illustrates the typical file structure for Vite entrypoints and components within a Ruby project. It highlights the roles of `sourceCodeDir` and `entrypointsDir`. ```text app/frontend: sourceCodeDir ├── entrypoints: entrypointsDir │ # only Vite entry files here │ │── application.js │ └── typography.css │── components: │ └── App.vue │── channels: │ │── index.js │ └── chat.js │── stylesheets: │ └── my_styles.css └── images: └── logo.svg ``` -------------------------------- ### Start Vite Dev Server for Tests Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/development.md Starts an additional Vite dev server specifically for integration tests, enabling Hot Module Replacement (HMR) and avoiding rebuilds. ```bash bin/vite dev --mode=test ``` -------------------------------- ### Vite Development Server Output Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/index.md This is the expected console output when the Vite development server starts successfully. ```text Vite ⚡️ Ruby ``` -------------------------------- ### Install vite_plugin_legacy Gem Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/plugin-legacy.md Add the vite_plugin_legacy gem to your application's Gemfile to enable legacy browser support. ```ruby gem 'vite_plugin_legacy' ``` -------------------------------- ### Basic Vite Configuration Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/config/index.md This snippet shows the default vite.config.ts setup when using vite-ruby. It includes importing defineConfig and RubyPlugin. ```js import { defineConfig } from 'vite' import RubyPlugin from 'vite-plugin-ruby' export default defineConfig({ plugins: [ RubyPlugin(), ], }) ``` -------------------------------- ### Importing Controllers with Vite 3 Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/migrating-to-vite-3.md Example of how import.meta.glob works in Vite 3, showing the change in module key paths. This can impact usages relying on full paths, such as with stimulus-vite-helpers. ```javascript const controllers = import.meta.glob('../**/*_controller.js', { eager: true }) ``` -------------------------------- ### Start Debugging Session with --inspect Flag Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/debugging.md Use the `--inspect` flag with Vite Ruby commands to start a Node.js debugging session. This enables the use of DevTools for setting breakpoints and inspecting code execution. ```bash vite --inspect ``` -------------------------------- ### Get Vite Ruby Information Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/development.md Displays information about Vite Ruby and related libraries. ```bash bin/vite info ``` -------------------------------- ### Replace require.context with import.meta.glob Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/migration.md Replace Webpacker's 'require.context' with Vite's 'import.meta.glob' for dynamic imports. This example shows how to import Stimulus controllers. ```diff - const context = require.context("./controllers", true, /\.js$/) + const controllers = import.meta.glob('./**/*_controller.js', { eager: true }) ``` -------------------------------- ### Using vite_stylesheet_tag Helper Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/development.md Example of how to include a stylesheet in your ERB view templates using the `vite_stylesheet_tag` helper. This assumes the stylesheet is located in the entrypoints directory. ```erb <%= vite_stylesheet_tag 'styles.scss' %> # app/frontend/entrypoints/styles.scss ``` -------------------------------- ### Configure Rails Plugin with Environment Variables Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/plugins.md Configure the Rails plugin to manage environment variables for development. This is part of the vite-plugin-rails setup. ```typescript plugins: [ Rails({ envVars: { RAILS_ENV: 'development' }, }), ], ``` -------------------------------- ### Configure vite-plugin-ruby in vite.config.js Source: https://github.com/elmassimo/vite_ruby/blob/main/vite-plugin-ruby/README.md Add vite-plugin-ruby to your Vite configuration file. This example shows integration with the Vue plugin. ```javascript // vite.config.js import Vue from '@vitejs/plugin-vue' // Example, could be using other plugins. import ViteRuby from 'vite-plugin-ruby' export default { plugins: [ Vue(), ViteRuby(), ], }; ``` -------------------------------- ### Configure Vite Ruby Source Directory Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/migration.md When Vite Ruby is installed, it checks for the existence of the 'app/javascript' directory. If found, it uses this directory in 'config/vite.json' instead of the default. ```json { "all": { "sourceCodeDir": "app/javascript", ... } } ``` -------------------------------- ### Reference Component JavaScript Tag Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/advanced.md Example of how to reference a component's JavaScript file using the vite_javascript_tag helper, based on the configured additionalEntrypoints. ```erb <%= vite_javascript_tag '/app/components/comment_component' %> ``` -------------------------------- ### Install Vite Ruby Rake Tasks Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/deployment.md Manually add Vite Ruby Rake tasks to your Rakefile if not using Rails. ```ruby require 'vite_ruby' ViteRuby.install_tasks ``` -------------------------------- ### Development Output for Vite JavaScript Tag Source: https://github.com/elmassimo/vite_ruby/blob/main/docs/src/guide/padrino.md Example of the HTML output generated by vite_javascript_tag when the development server is running. Dependencies are loaded directly by Vite, so extra tags are omitted. ```html