├── .husky ├── .gitignore ├── pre-commit └── commit-msg ├── .ruby-version ├── docs ├── pnpm-workspace.yaml ├── .npmrc ├── src │ ├── public │ │ ├── _headers │ │ ├── logo.png │ │ ├── banner.png │ │ ├── ruby-logo.png │ │ └── ruby-logo-margin.png │ ├── vite.config.ts │ └── index.md ├── .vitepress │ └── theme │ │ ├── index.js │ │ └── components │ │ └── Quote.vue ├── tsconfig.json ├── env.d.ts ├── package.json └── .stylelintrc.js ├── test ├── test_app │ ├── some.config.js │ ├── app │ │ ├── frontend │ │ │ └── entrypoints │ │ │ │ ├── sassy.scss │ │ │ │ ├── colored.css │ │ │ │ ├── example_import.js │ │ │ │ └── application.js │ │ └── views │ │ │ └── layouts │ │ │ └── application.html.erb │ ├── config │ │ ├── vite_public_dir.json │ │ ├── vite_additional_paths.json │ │ ├── environment.rb │ │ ├── vite_public_dir.rb │ │ ├── vite.json │ │ └── application.rb │ ├── Rakefile │ ├── config.ru │ ├── vite.config.ts │ ├── package.json │ ├── .gitignore │ ├── public │ │ └── vite-production │ │ │ └── .vite │ │ │ └── manifest-assets.json │ └── bin │ │ └── vite ├── mounted_app │ ├── test │ │ └── dummy │ │ │ ├── .gitignore │ │ │ ├── Rakefile │ │ │ ├── config │ │ │ ├── environment.rb │ │ │ ├── initializers │ │ │ │ └── content_security_policy.rb │ │ │ ├── vite.json │ │ │ └── application.rb │ │ │ ├── config.ru │ │ │ ├── package.json │ │ │ ├── app │ │ │ └── views │ │ │ │ └── layouts │ │ │ │ └── application.html.erb │ │ │ └── bin │ │ │ ├── m │ │ │ ├── pry │ │ │ ├── rake │ │ │ ├── thor │ │ │ ├── rackup │ │ │ ├── rails │ │ │ ├── byebug │ │ │ ├── coderay │ │ │ ├── rubocop │ │ │ ├── spring │ │ │ ├── nokogiri │ │ │ ├── ruby-parse │ │ │ ├── sprockets │ │ │ └── ruby-rewrite │ └── Rakefile ├── mode_test.rb ├── leading_slash_benchmark.rb ├── file_operations_benchmark.rb ├── dev_server_test.rb └── runner_test.rb ├── .npmrc ├── examples ├── rails │ ├── public │ │ ├── favicon.ico │ │ ├── apple-touch-icon.png │ │ ├── apple-touch-icon-precomposed.png │ │ └── robots.txt │ ├── .browserslistrc │ ├── .ruby-version │ ├── .rspec │ ├── app │ │ ├── frontend │ │ │ ├── packs │ │ │ │ └── not_used.js │ │ │ ├── entrypoints │ │ │ │ ├── styles-plain.css │ │ │ │ ├── styles-less.less │ │ │ │ ├── styles-stylus.stylus │ │ │ │ ├── example_import.js │ │ │ │ ├── styles.scss │ │ │ │ └── application.ts │ │ │ ├── styles │ │ │ │ ├── logo.scss │ │ │ │ └── theme.css │ │ │ ├── images │ │ │ │ └── logo.png │ │ │ ├── outer_import.ts │ │ │ ├── channels │ │ │ │ └── consumer.js │ │ │ ├── components │ │ │ │ ├── Hero.jsx │ │ │ │ └── Version.jsx │ │ │ └── integrations │ │ │ │ ├── honeybadger.ts │ │ │ │ └── bugsnag.ts │ │ ├── views │ │ │ ├── layouts │ │ │ │ ├── mailer.text.erb │ │ │ │ ├── mailer.html.erb │ │ │ │ └── application.html.erb │ │ │ └── home │ │ │ │ └── index.html.erb │ │ ├── helpers │ │ │ ├── home_helper.rb │ │ │ └── application_helper.rb │ │ ├── controllers │ │ │ ├── application_controller.rb │ │ │ └── home_controller.rb │ │ ├── models │ │ │ └── application_record.rb │ │ ├── channels │ │ │ └── application_cable │ │ │ │ ├── channel.rb │ │ │ │ └── connection.rb │ │ ├── mailers │ │ │ └── application_mailer.rb │ │ └── jobs │ │ │ └── application_job.rb │ ├── Procfile │ ├── .env.development │ ├── env.d.ts │ ├── example_engine │ │ ├── app │ │ │ ├── assets │ │ │ │ ├── images │ │ │ │ │ └── administrator │ │ │ │ │ │ └── .keep │ │ │ │ ├── config │ │ │ │ │ └── administrator_manifest.js │ │ │ │ └── stylesheets │ │ │ │ │ └── administrator │ │ │ │ │ └── application.css │ │ │ ├── views │ │ │ │ ├── administrator │ │ │ │ │ └── timer │ │ │ │ │ │ └── index.html.erb │ │ │ │ └── layouts │ │ │ │ │ └── administrator │ │ │ │ │ └── application.html.erb │ │ │ ├── jobs │ │ │ │ └── administrator │ │ │ │ │ └── application_job.rb │ │ │ ├── controllers │ │ │ │ └── administrator │ │ │ │ │ ├── application_controller.rb │ │ │ │ │ └── timer_controller.rb │ │ │ ├── models │ │ │ │ └── administrator │ │ │ │ │ └── application_record.rb │ │ │ ├── frontend │ │ │ │ ├── entrypoints │ │ │ │ │ └── application.js │ │ │ │ └── timer.js │ │ │ └── helpers │ │ │ │ └── administrator │ │ │ │ └── application_helper.rb │ │ ├── lib │ │ │ ├── administrator │ │ │ │ ├── version.rb │ │ │ │ └── engine.rb │ │ │ ├── tasks │ │ │ │ └── administrator_tasks.rake │ │ │ └── administrator.rb │ │ ├── config │ │ │ ├── routes.rb │ │ │ └── vite.json │ │ ├── package.json │ │ ├── vite.config.ts │ │ ├── Gemfile │ │ ├── .gitignore │ │ ├── Rakefile │ │ ├── bin │ │ │ ├── rake │ │ │ ├── vite │ │ │ └── rails │ │ ├── administrator.gemspec │ │ ├── MIT-LICENSE │ │ └── README.md │ ├── pnpm-workspace.yaml │ ├── Procfile.dev │ ├── .npmrc │ ├── bin │ │ ├── docker_gems │ │ ├── docker │ │ ├── live │ │ ├── assets │ │ ├── docker_setup │ │ ├── preview │ │ ├── serve │ │ ├── rake │ │ ├── rails │ │ ├── yarn │ │ ├── spring │ │ ├── vite │ │ └── rspec │ ├── docker-rails.sh │ ├── .dockerignore │ ├── docker-vite.sh │ ├── config │ │ ├── spring.rb │ │ ├── vite.rb │ │ ├── routes.rb │ │ ├── environment.rb │ │ ├── initializers │ │ │ ├── mime_types.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── application_controller_renderer.rb │ │ │ ├── cookies_serializer.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── wrap_parameters.rb │ │ │ └── inflections.rb │ │ ├── cable.yml │ │ ├── boot.rb │ │ ├── vite.json │ │ ├── credentials.yml.enc │ │ ├── database.yml │ │ └── locales │ │ │ └── en.yml │ ├── config.ru │ ├── spec │ │ ├── features │ │ │ ├── admin │ │ │ │ └── home_spec.rb │ │ │ └── home_spec.rb │ │ └── support │ │ │ ├── urls.rb │ │ │ └── capybara.rb │ ├── db │ │ ├── seeds.rb │ │ └── schema.rb │ ├── plugins │ │ └── bugsnag.ts │ ├── Rakefile │ ├── test_helpers │ │ ├── base_test_helper.rb │ │ └── home_test_helper.rb │ ├── Dockerfile │ ├── tsconfig.json │ ├── README.md │ ├── package.json │ └── .gitignore ├── hanami_bookshelf │ ├── db │ │ ├── schema.sql │ │ └── migrations │ │ │ └── .gitkeep │ ├── public │ │ └── .gitkeep │ ├── spec │ │ ├── support │ │ │ ├── .gitkeep │ │ │ └── capybara.rb │ │ ├── web │ │ │ ├── features │ │ │ │ └── .gitkeep │ │ │ ├── controllers │ │ │ │ ├── .gitkeep │ │ │ │ └── dashboard │ │ │ │ │ └── index_spec.rb │ │ │ └── views │ │ │ │ ├── application_layout_spec.rb │ │ │ │ └── dashboard │ │ │ │ └── index_spec.rb │ │ ├── hanami_bookshelf │ │ │ ├── entities │ │ │ │ └── .gitkeep │ │ │ ├── mailers │ │ │ │ └── .gitkeep │ │ │ └── repositories │ │ │ │ └── .gitkeep │ │ └── features_helper.rb │ ├── .ruby-version │ ├── apps │ │ └── web │ │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .gitkeep │ │ │ ├── javascripts │ │ │ │ └── .gitkeep │ │ │ ├── stylesheets │ │ │ │ └── .gitkeep │ │ │ └── favicon.ico │ │ │ ├── controllers │ │ │ ├── .gitkeep │ │ │ └── dashboard │ │ │ │ └── index.rb │ │ │ ├── frontend │ │ │ ├── entrypoints │ │ │ │ ├── example_import.js │ │ │ │ ├── application.ts │ │ │ │ ├── images │ │ │ │ │ └── logo.png │ │ │ │ └── styles.scss │ │ │ ├── outer_import.js │ │ │ ├── index.css │ │ │ └── styles │ │ │ │ └── theme.css │ │ │ ├── views │ │ │ ├── application_layout.rb │ │ │ └── dashboard │ │ │ │ └── index.rb │ │ │ ├── templates │ │ │ ├── dashboard │ │ │ │ └── index.html.erb │ │ │ └── application.html.erb │ │ │ └── config │ │ │ └── routes.rb │ ├── config │ │ ├── initializers │ │ │ ├── .gitkeep │ │ │ └── vite_hanami.rb │ │ ├── boot.rb │ │ └── vite.json │ ├── .rspec │ ├── lib │ │ └── hanami_bookshelf.rb │ ├── .hanamirc │ ├── bin │ │ ├── serve │ │ ├── rake │ │ └── vite │ ├── config.ru │ ├── Procfile.dev │ ├── Procfile │ ├── .gitignore │ ├── vite.config.ts │ ├── Rakefile │ ├── .env.test │ ├── .env.development │ ├── package.json │ ├── README.md │ └── Gemfile └── padrino_blog_tutorial │ ├── Procfile.dev │ ├── bin │ ├── serve │ ├── rake │ ├── vite │ └── padrino │ ├── public │ └── favicon.ico │ ├── app │ ├── frontend │ │ ├── entrypoints │ │ │ ├── application.js │ │ │ └── styles.css │ │ └── styles │ │ │ └── theme.css │ ├── controllers │ │ └── posts.rb │ ├── views │ │ ├── posts │ │ │ └── index.haml │ │ └── layouts │ │ │ └── application.haml │ └── app.rb │ ├── Rakefile │ ├── package.json │ ├── vite.config.ts │ ├── .components │ ├── .gitignore │ ├── Gemfile │ ├── config.ru │ └── config │ ├── vite.json │ ├── apps.rb │ └── boot.rb ├── vite-plugin-rails ├── .npmrc ├── .gitignore ├── example │ ├── app │ │ ├── frontend │ │ │ ├── log.ts │ │ │ ├── entrypoints │ │ │ │ ├── sassy.scss │ │ │ │ ├── frameworks │ │ │ │ │ └── vue.js │ │ │ │ ├── main.ts │ │ │ │ └── app.css │ │ │ ├── images │ │ │ │ └── logo.png │ │ │ ├── index.html │ │ │ ├── ssr │ │ │ │ └── ssr.ts │ │ │ └── App.vue │ │ └── assets │ │ │ ├── external.js │ │ │ ├── theme.css │ │ │ └── logo.png │ ├── shims.d.ts │ ├── vite.config.ts │ ├── config │ │ └── vite.json │ └── package.json ├── env.d.ts ├── tsup.config.ts ├── vitest.config.ts ├── tests │ ├── package.json │ └── tsconfig.json ├── tsconfig.json ├── scripts │ └── postbuild.mjs ├── CHANGELOG.md └── LICENSE.txt ├── vite-plugin-ruby ├── .npmrc ├── example │ ├── app │ │ ├── incorrect │ │ │ └── ssr │ │ │ │ ├── ssr.js │ │ │ │ └── ssr.ts │ │ ├── frontend │ │ │ ├── log.ts │ │ │ ├── entrypoints │ │ │ │ ├── sassy.scss │ │ │ │ ├── frameworks │ │ │ │ │ └── vue.js │ │ │ │ ├── main.ts │ │ │ │ └── app.css │ │ │ ├── images │ │ │ │ └── logo.png │ │ │ ├── index.html │ │ │ ├── App.vue │ │ │ └── ssr │ │ │ │ └── ssr.ts │ │ └── assets │ │ │ ├── external.js │ │ │ ├── theme.css │ │ │ └── logo.png │ ├── shims.d.ts │ ├── vite.config.ts │ ├── config │ │ └── vite.json │ └── package.json ├── .gitignore ├── env.d.ts ├── tests │ ├── package.json │ └── tsconfig.json ├── vitest.config.ts ├── tsup.config.ts ├── tsconfig.json ├── default.vite.json ├── src │ └── constants.ts ├── LICENSE.txt └── LICENSE ├── vite_rails ├── templates │ ├── Procfile.dev │ ├── config │ │ └── rails-vite.json │ └── entrypoints │ │ └── application.js ├── bin │ └── release ├── lib │ ├── vite_rails │ │ ├── version.rb │ │ └── config.rb │ ├── tasks │ │ └── vite.rake │ └── vite_rails.rb ├── Rakefile ├── vite_rails.gemspec └── LICENSE.txt ├── vite_ruby ├── bin │ ├── console │ └── release ├── Rakefile ├── templates │ ├── config │ │ ├── vite.config.ts │ │ └── vite.json │ └── entrypoints │ │ └── application.js ├── lib │ └── vite_ruby │ │ ├── cli │ │ ├── version.rb │ │ ├── upgrade_packages.rb │ │ ├── dev.rb │ │ ├── clobber.rb │ │ ├── build.rb │ │ ├── upgrade.rb │ │ └── ssr.rb │ │ ├── version.rb │ │ ├── error.rb │ │ ├── missing_executable_error.rb │ │ └── io.rb ├── exe │ └── vite ├── default.vite.json └── LICENSE.txt ├── .eslintignore ├── vite_hanami ├── bin │ └── release ├── lib │ ├── vite_hanami │ │ └── version.rb │ └── vite_hanami.rb ├── Rakefile ├── templates │ └── config │ │ └── hanami-vite.json ├── CHANGELOG.md ├── vite_hanami.gemspec └── LICENSE.txt ├── vite_padrino ├── bin │ └── release ├── lib │ ├── vite_padrino │ │ ├── version.rb │ │ └── installation.rb │ └── vite_padrino.rb ├── Rakefile ├── templates │ └── config │ │ └── padrino-vite.json ├── vite_padrino.gemspec └── LICENSE.txt ├── vite_plugin_legacy ├── bin │ └── release ├── lib │ ├── vite_plugin_legacy │ │ ├── installation.rb │ │ ├── version.rb │ │ └── engine.rb │ └── vite_plugin_legacy.rb ├── Rakefile ├── vite_plugin_legacy.gemspec └── LICENSE.txt ├── vite_rails_legacy ├── lib │ ├── tasks │ │ └── vite.rake │ ├── vite_rails_legacy │ │ ├── version.rb │ │ ├── config.rb │ │ └── engine.rb │ └── vite_rails_legacy.rb ├── Rakefile ├── templates │ ├── config │ │ └── rails-vite.json │ └── entrypoints │ │ └── application.js ├── vite_rails_legacy.gemspec └── LICENSE.txt ├── gemfiles ├── Gemfile-rails.7.0.x ├── Gemfile-rails.7.1.x ├── Gemfile-rails.7.2.x ├── Gemfile-rails.8.0.x └── Gemfile-rails-edge ├── .eslintrc.cjs ├── pnpm-workspace.yaml ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ ├── rubocop.yml │ └── js.yml └── ISSUE_TEMPLATE │ ├── config.yml │ └── feature_request.md ├── Rakefile ├── bin ├── snapshot ├── rake ├── rubocop └── m ├── netlify.toml ├── Gemfile ├── tsconfig.json ├── .rubocop_todo.yml ├── .gitignore ├── scripts └── verifyCommit.cjs ├── LICENSE.txt └── package.json /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.3.6 2 | -------------------------------------------------------------------------------- /docs/pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/test_app/some.config.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | -------------------------------------------------------------------------------- /examples/rails/public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.npmrc: -------------------------------------------------------------------------------- 1 | ignore-workspace-root-check=true -------------------------------------------------------------------------------- /examples/hanami_bookshelf/db/schema.sql: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/public/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/.browserslistrc: -------------------------------------------------------------------------------- 1 | defaults 2 | -------------------------------------------------------------------------------- /examples/rails/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.0.3 2 | -------------------------------------------------------------------------------- /examples/rails/public/apple-touch-icon.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/db/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/support/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/packs/not_used.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/web/features/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/Procfile: -------------------------------------------------------------------------------- 1 | web: bin/rails server 2 | -------------------------------------------------------------------------------- /vite-plugin-rails/.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | -------------------------------------------------------------------------------- /vite-plugin-ruby/.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/incorrect/ssr/ssr.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/incorrect/ssr/ssr.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-3.1.1 2 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/assets/images/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/controllers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/config/initializers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/web/controllers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/assets/javascripts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/assets/stylesheets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vite_rails/templates/Procfile.dev: -------------------------------------------------------------------------------- 1 | web: bin/rails server 2 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/hanami_bookshelf/entities/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/hanami_bookshelf/mailers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/.env.development: -------------------------------------------------------------------------------- 1 | HEROKU_RELEASE_VERSION=local 2 | -------------------------------------------------------------------------------- /examples/rails/app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /examples/rails/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/assets/images/administrator/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/hanami_bookshelf/repositories/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/rails/pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - example_engine/ 3 | -------------------------------------------------------------------------------- /vite-plugin-ruby/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | public -------------------------------------------------------------------------------- /vite-plugin-rails/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | public -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/log.ts: -------------------------------------------------------------------------------- 1 | console.log('Vite ⚡️ Rails') 2 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/log.ts: -------------------------------------------------------------------------------- 1 | console.log('Vite ⚡️ Rails') 2 | -------------------------------------------------------------------------------- /vite_ruby/bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | pry -r './lib/vite_ruby.rb' 3 | -------------------------------------------------------------------------------- /examples/rails/Procfile.dev: -------------------------------------------------------------------------------- 1 | vite: bin/vite dev 2 | web: bin/rails s --port 3000 3 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/lib/hanami_bookshelf.rb: -------------------------------------------------------------------------------- 1 | module HanamiBookshelf 2 | end 3 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/Procfile.dev: -------------------------------------------------------------------------------- 1 | vite: bin/vite dev 2 | web: bin/serve 3 | -------------------------------------------------------------------------------- /examples/rails/.npmrc: -------------------------------------------------------------------------------- 1 | ignore-workspace-root-check="true" 2 | auto-install-peers=true 3 | -------------------------------------------------------------------------------- /test/test_app/app/frontend/entrypoints/sassy.scss: -------------------------------------------------------------------------------- 1 | .colored { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /vite_rails/bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd .. && pnpm release vite_rails "$@" 3 | -------------------------------------------------------------------------------- /vite_ruby/bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd .. && pnpm release vite_ruby "$@" 3 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | coverage/ 3 | build/ 4 | examples/ 5 | public/ 6 | node_modules/ 7 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/config/boot.rb: -------------------------------------------------------------------------------- 1 | require_relative './environment' 2 | Hanami.boot 3 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/bin/serve: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | bin/padrino s "$@" 4 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/styles-plain.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/test_app/app/frontend/entrypoints/colored.css: -------------------------------------------------------------------------------- 1 | .colored { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/test_app/app/frontend/entrypoints/example_import.js: -------------------------------------------------------------------------------- 1 | export default () => 'Example' 2 | -------------------------------------------------------------------------------- /vite_hanami/bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd .. && pnpm release vite_hanami "$@" 3 | -------------------------------------------------------------------------------- /vite_padrino/bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd .. && pnpm release vite_padrino "$@" 3 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.hanamirc: -------------------------------------------------------------------------------- 1 | project=hanami_bookshelf 2 | test=rspec 3 | template=erb 4 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/bin/serve: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | bundle exec hanami server 4 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/config.ru: -------------------------------------------------------------------------------- 1 | require './config/environment' 2 | 3 | run Hanami.app 4 | -------------------------------------------------------------------------------- /examples/rails/bin/docker_gems: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | bundle check || bundle install 5 | -------------------------------------------------------------------------------- /docs/src/public/_headers: -------------------------------------------------------------------------------- 1 | /assets/* 2 | cache-control: max-age=31536000 3 | cache-control: immutable -------------------------------------------------------------------------------- /docs/src/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/docs/src/public/logo.png -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/styles-less.less: -------------------------------------------------------------------------------- 1 | .class { 2 | property: 1px * 2px; 3 | } 4 | -------------------------------------------------------------------------------- /docs/src/public/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/docs/src/public/banner.png -------------------------------------------------------------------------------- /examples/hanami_bookshelf/Procfile.dev: -------------------------------------------------------------------------------- 1 | web: bundle exec hanami server 2 | vite: bundle exec vite dev 3 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/entrypoints/example_import.js: -------------------------------------------------------------------------------- 1 | console.log('Vite ⚡️ Hanami') 2 | -------------------------------------------------------------------------------- /vite_plugin_legacy/bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | cd .. && pnpm release vite_plugin_legacy "$@" 3 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | node scripts/verifyCommit.cjs "$1" 5 | -------------------------------------------------------------------------------- /docs/src/public/ruby-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/docs/src/public/ruby-logo.png -------------------------------------------------------------------------------- /examples/rails/app/helpers/home_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module HomeHelper 4 | end 5 | -------------------------------------------------------------------------------- /examples/rails/bin/docker: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | docker-compose up --build --abort-on-container-exit 5 | -------------------------------------------------------------------------------- /test/test_app/config/vite_public_dir.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "publicDir": "../public" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/assets/external.js: -------------------------------------------------------------------------------- 1 | console.log('This file is a manually configured entrypoint') 2 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/assets/external.js: -------------------------------------------------------------------------------- 1 | console.log('This file is a manually configured entrypoint') 2 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/outer_import.js: -------------------------------------------------------------------------------- 1 | console.log('Improving your development experience!') 2 | -------------------------------------------------------------------------------- /vite-plugin-rails/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /vite-plugin-ruby/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/entrypoints/sassy.scss: -------------------------------------------------------------------------------- 1 | $red: #cc0000; 2 | 3 | h1 { 4 | color: $red; 5 | } 6 | -------------------------------------------------------------------------------- /examples/rails/bin/live: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | bin/vite clobber --mode=production 5 | bin/assets 6 | bin/serve 7 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/entrypoints/sassy.scss: -------------------------------------------------------------------------------- 1 | $red: #cc0000; 2 | 3 | h1 { 4 | color: $red; 5 | } 6 | -------------------------------------------------------------------------------- /docs/src/public/ruby-logo-margin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/docs/src/public/ruby-logo-margin.png -------------------------------------------------------------------------------- /examples/rails/app/frontend/styles/logo.scss: -------------------------------------------------------------------------------- 1 | $size: 0; 2 | 3 | .logo { 4 | height: $size; 5 | opacity: $size; 6 | } 7 | -------------------------------------------------------------------------------- /examples/rails/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationHelper 4 | end 5 | -------------------------------------------------------------------------------- /test/test_app/config/vite_additional_paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "watchAdditionalPaths": ["config/*"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /vite_rails_legacy/lib/tasks/vite.rake: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | ViteRuby.install_tasks 5 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/assets/config/administrator_manifest.js: -------------------------------------------------------------------------------- 1 | //= link_directory ../stylesheets/administrator .css 2 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/assets/theme.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --color: #2c3e50; 3 | } 4 | 5 | .hidden { 6 | display: none; 7 | } 8 | -------------------------------------------------------------------------------- /vite_hanami/lib/vite_hanami/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ViteHanami 4 | VERSION = "3.0.0" 5 | end 6 | -------------------------------------------------------------------------------- /vite_plugin_legacy/lib/vite_plugin_legacy/installation.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_plugin_legacy" 4 | -------------------------------------------------------------------------------- /vite_rails/lib/vite_rails/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ViteRails 4 | VERSION = "3.0.19" 5 | end 6 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/config/initializers/vite_hanami.rb: -------------------------------------------------------------------------------- 1 | require 'vite_hanami' 2 | 3 | ViteRuby.instance.logger = Hanami.logger 4 | -------------------------------------------------------------------------------- /examples/rails/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/assets/theme.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --color: #2c3e50; 3 | } 4 | 5 | .hidden { 6 | display: none; 7 | } 8 | -------------------------------------------------------------------------------- /vite_padrino/lib/vite_padrino/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module VitePadrino 4 | VERSION = "3.0.0" 5 | end 6 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/examples/rails/app/frontend/images/logo.png -------------------------------------------------------------------------------- /examples/rails/app/frontend/outer_import.ts: -------------------------------------------------------------------------------- 1 | export const tagline = 'Improving your development experience!' 2 | 3 | console.log(tagline) 4 | -------------------------------------------------------------------------------- /test/test_app/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "config/application" 4 | 5 | Rails.application.load_tasks 6 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/vite-plugin-ruby/example/app/assets/logo.png -------------------------------------------------------------------------------- /examples/rails/bin/assets: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Compiles the app assets in production mode. 4 | RAILS_ENV=production bin/rake assets:precompile 5 | -------------------------------------------------------------------------------- /examples/rails/bin/docker_setup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | docker-compose build && docker-compose run --rm --entrypoint "bin/setup" rails 5 | -------------------------------------------------------------------------------- /examples/rails/docker-rails.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | bin/docker_gems 6 | rm -f tmp/pids/server.pid 7 | bin/rails server -b 0.0.0.0 8 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/vite-plugin-rails/example/app/assets/logo.png -------------------------------------------------------------------------------- /vite_rails_legacy/lib/vite_rails_legacy/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ViteRailsLegacy 4 | VERSION = "3.1.0" 5 | end 6 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/examples/padrino_blog_tutorial/public/favicon.ico -------------------------------------------------------------------------------- /examples/rails/.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | vendor 3 | tmp 4 | log 5 | test 6 | .envrc 7 | public/packs 8 | public/vite* 9 | README.md 10 | -------------------------------------------------------------------------------- /vite_plugin_legacy/lib/vite_plugin_legacy/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module VitePluginLegacy 4 | VERSION = "3.0.2" 5 | end 6 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/styles-stylus.stylus: -------------------------------------------------------------------------------- 1 | table 2 | for row in 1 2 3 4 5 3 | tr:nth-child({row}) 4 | height: 10px * row 5 | -------------------------------------------------------------------------------- /examples/rails/example_engine/lib/administrator/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | VERSION = '0.1.0' 5 | end 6 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "config/application" 4 | 5 | Rails.application.load_tasks 6 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/examples/hanami_bookshelf/apps/web/assets/favicon.ico -------------------------------------------------------------------------------- /examples/rails/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationController < ActionController::Base 4 | end 5 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "application" 4 | 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/vite-plugin-rails/example/app/frontend/images/logo.png -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/vite-plugin-ruby/example/app/frontend/images/logo.png -------------------------------------------------------------------------------- /examples/rails/app/controllers/home_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class HomeController < ApplicationController 4 | def index; end 5 | end 6 | -------------------------------------------------------------------------------- /examples/rails/example_engine/config/routes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Administrator::Engine.routes.draw do 4 | get '/', to: 'timer#index' 5 | end 6 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/entrypoints/frameworks/vue.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from '~/App.vue' 3 | createApp(App).mount('#app') 4 | -------------------------------------------------------------------------------- /vite_hanami/lib/vite_hanami.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | require "vite_hanami/version" 5 | require "vite_hanami/tag_helpers" 6 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/index.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | font-family: Helvetica; 3 | font-size: 4rem; 4 | margin-top: 4rem; 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /examples/rails/bin/preview: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Starts the Rails server in production mode. 4 | RAILS_SERVE_STATIC_FILES=true RAILS_ENV=production bin/rails s "$@" 5 | -------------------------------------------------------------------------------- /examples/rails/example_engine/lib/tasks/administrator_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :administrator do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/entrypoints/frameworks/vue.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from '~/App.vue' 3 | createApp(App).mount('#app') 4 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/entrypoints/main.ts: -------------------------------------------------------------------------------- 1 | import '~/entrypoints/app.css' 2 | import '~/log' 3 | import './frameworks/vue' 4 | import '@assets/theme.css' 5 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/entrypoints/main.ts: -------------------------------------------------------------------------------- 1 | import '~/entrypoints/app.css' 2 | import '~/log' 3 | import './frameworks/vue' 4 | import '@assets/theme.css' 5 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/entrypoints/application.ts: -------------------------------------------------------------------------------- 1 | import '~/styles/theme.css' 2 | import '~/entrypoints/example_import.js' 3 | import '~/outer_import.js' 4 | -------------------------------------------------------------------------------- /examples/rails/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationRecord < ActiveRecord::Base 4 | self.abstract_class = true 5 | end 6 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/views/administrator/timer/index.html.erb: -------------------------------------------------------------------------------- 1 |

Rails Engine

2 | 3 |

Seconds elapsed since page load: 0

4 | -------------------------------------------------------------------------------- /examples/rails/example_engine/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "vite": "^4.3.0", 4 | "vite-plugin-ruby": "^3.2.0" 5 | }, 6 | "type": "module" 7 | } 8 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/Procfile: -------------------------------------------------------------------------------- 1 | # Procfile 2 | web: bundle exec puma -t ${PUMA_MIN_THREADS:-5}:${PUMA_MAX_THREADS:-5} -w ${PUMA_WORKERS:-2} -p $PORT -e ${RACK_ENV:-production} 3 | -------------------------------------------------------------------------------- /examples/rails/bin/serve: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Starts the Rails server in development mode. 4 | RAILS_SERVE_STATIC_FILES=true RAILS_ENV=production bin/rails s --port 5050 "$@" 5 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/views/application_layout.rb: -------------------------------------------------------------------------------- 1 | module Web 2 | module Views 3 | class ApplicationLayout 4 | include Web::Layout 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/frontend/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | import 'bulma/css/bulma.min.css' 2 | 3 | import '~/styles/theme.css' 4 | 5 | console.log('Vite ⚡️ Padrino') 6 | -------------------------------------------------------------------------------- /examples/rails/docker-vite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | bin/docker_gems 6 | yarn install 7 | cd example_engine 8 | yarn install 9 | cd .. 10 | 11 | bin/vite dev 12 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.config.content_security_policy do |policy| 4 | end 5 | -------------------------------------------------------------------------------- /vite-plugin-ruby/tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-ruby-tests", 3 | "private": true, 4 | "devDependencies": { 5 | "vite-plugin-ruby": "workspace:*" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require 'padrino-core/cli/rake' 3 | 4 | PadrinoTasks.init 5 | require 'vite_padrino' 6 | ViteRuby.install_tasks 7 | 8 | -------------------------------------------------------------------------------- /examples/rails/app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationCable 4 | class Channel < ActionCable::Channel::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /examples/rails/config/spring.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Spring.watch( 4 | '.ruby-version', 5 | '.rbenv-vars', 6 | 'tmp/restart.txt', 7 | 'tmp/caching-dev.txt', 8 | ) 9 | -------------------------------------------------------------------------------- /examples/rails/config/vite.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ViteRuby.env['ADMINISTRATOR_ASSETS_PATH'] = 4 | "#{ Gem.loaded_specs['administrator'].full_gem_path }/app/frontend" 5 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/entrypoints/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ElMassimo/vite_ruby/HEAD/examples/hanami_bookshelf/apps/web/frontend/entrypoints/images/logo.png -------------------------------------------------------------------------------- /examples/rails/example_engine/app/jobs/administrator/application_job.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | class ApplicationJob < ActiveJob::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /examples/rails/example_engine/lib/administrator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'administrator/version' 4 | require 'administrator/engine' 5 | 6 | module Administrator 7 | end 8 | -------------------------------------------------------------------------------- /test/test_app/config/environment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "application" 4 | 5 | Rails.backtrace_cleaner.remove_silencers! 6 | Rails.application.initialize! 7 | -------------------------------------------------------------------------------- /examples/rails/app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ApplicationCable 4 | class Connection < ActionCable::Connection::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /test/mounted_app/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/setup" 4 | 5 | APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) 6 | load "rails/tasks/engine.rake" 7 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/controllers/posts.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | BlogTutorial::App.controllers :posts do 4 | get :index do 5 | render 'posts/index' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /examples/rails/app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationMailer < ActionMailer::Base 4 | default from: 'from@example.com' 5 | layout 'mailer' 6 | end 7 | -------------------------------------------------------------------------------- /examples/rails/config/routes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Rails.application.routes.draw do 4 | root to: 'home#index', as: :home 5 | 6 | mount Administrator::Engine => '/admin' 7 | end 8 | -------------------------------------------------------------------------------- /test/test_app/config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file allows the `Rails.root` to be correctly determined. 4 | 5 | require_relative "config/environment" 6 | 7 | run Rails.application 8 | -------------------------------------------------------------------------------- /test/test_app/config/vite_public_dir.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ViteRuby.configure(public_output_dir: "from_ruby") 4 | ViteRuby.env["EXAMPLE_PATH"] = Gem.loaded_specs["rails"].full_gem_path 5 | -------------------------------------------------------------------------------- /test/test_app/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import RubyPlugin from 'vite-plugin-ruby' 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | RubyPlugin(), 7 | ], 8 | }) 9 | -------------------------------------------------------------------------------- /vite_hanami/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_hanami@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_rails/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_rails@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_ruby/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_ruby@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /examples/rails/config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file is used by Rack-based servers to start the application. 4 | 5 | require_relative 'config/environment' 6 | 7 | run Rails.application 8 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.7.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 7.0.3' 4 | 5 | gemspec path: '../vite_ruby' 6 | gemspec path: '../vite_rails' 7 | gemspec path: '../vite_plugin_legacy' 8 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.7.1.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 7.1.0' 4 | 5 | gemspec path: '../vite_ruby' 6 | gemspec path: '../vite_rails' 7 | gemspec path: '../vite_plugin_legacy' 8 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.7.2.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 7.2.0' 4 | 5 | gemspec path: '../vite_ruby' 6 | gemspec path: '../vite_rails' 7 | gemspec path: '../vite_plugin_legacy' 8 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails.8.0.x: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 8.0.0' 4 | 5 | gemspec path: '../vite_ruby' 6 | gemspec path: '../vite_rails' 7 | gemspec path: '../vite_plugin_legacy' 8 | -------------------------------------------------------------------------------- /vite_padrino/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_padrino@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_rails/lib/tasks/vite.rake: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | ViteRuby.install_tasks 5 | Rake::Task["vite:verify_install"].enhance([:environment]) if Gem.loaded_specs["rails"] 6 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.gitignore: -------------------------------------------------------------------------------- 1 | /db/*.sqlite 2 | /public/assets* 3 | /tmp 4 | .env.local 5 | .env.*.local 6 | 7 | # Vite Ruby 8 | /public/vite* 9 | node_modules 10 | *.local 11 | .DS_Store 12 | 13 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@mussi/eslint-config'], 3 | rules: { 4 | 'react/react-in-jsx-scope': 'off', 5 | 'import/named': 'off', 6 | 'no-prototype-builtins': 'off', 7 | }, 8 | } 9 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import RubyPlugin from 'vite-plugin-ruby' 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | RubyPlugin(), 7 | ], 8 | }) 9 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "vite": "^3.0.0", 4 | "vite-plugin-ruby":"^3.0.8" 5 | }, 6 | "dependencies": { 7 | "bulma": "^0.9.2" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/rails/config/environment.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Load the Rails application. 4 | require_relative 'application' 5 | 6 | # Initialize the Rails application. 7 | Rails.application.initialize! 8 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - vite-plugin-ruby/ 3 | - vite-plugin-ruby/example/ 4 | - vite-plugin-ruby/tests/ 5 | - vite-plugin-rails/ 6 | - vite-plugin-rails/example/ 7 | - vite-plugin-rails/tests/ 8 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file allows the `Rails.root` to be correctly determined. 4 | 5 | require_relative "config/environment" 6 | 7 | run Rails.application 8 | -------------------------------------------------------------------------------- /vite-plugin-rails/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import type { Options } from 'tsup' 2 | export const tsup: Options = { 3 | clean: true, 4 | dts: true, 5 | shims: true, 6 | target: 'node18', 7 | format: ['esm', 'cjs'], 8 | } 9 | -------------------------------------------------------------------------------- /vite_plugin_legacy/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_plugin_legacy@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_rails_legacy/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | 5 | class Bundler::GemHelper 6 | def version_tag 7 | "vite_rails_legacy@#{version}" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_ruby/templates/config/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import RubyPlugin from 'vite-plugin-ruby' 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | RubyPlugin(), 7 | ], 8 | }) 9 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/views/dashboard/index.rb: -------------------------------------------------------------------------------- 1 | module Web 2 | module Views 3 | module Dashboard 4 | class Index 5 | include Web::View 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import RubyPlugin from 'vite-plugin-ruby' 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | RubyPlugin(), 7 | ], 8 | }) 9 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/controllers/administrator/application_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | class ApplicationController < ActionController::Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /examples/rails/example_engine/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import RubyPlugin from 'vite-plugin-ruby' 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | RubyPlugin(), 7 | ], 8 | }) 9 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 📖 2 | 3 | This pull request 4 | 5 | ### Background 📜 6 | 7 | This was happening because 8 | 9 | ### The Fix 🔨 10 | 11 | By changing 12 | 13 | ### Screenshots 📷 14 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/support/capybara.rb: -------------------------------------------------------------------------------- 1 | module RSpec 2 | module FeatureExampleGroup 3 | def self.included(group) 4 | group.metadata[:type] = :feature 5 | Capybara.app = Hanami.app 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/models/administrator/application_record.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | class ApplicationRecord < ActiveRecord::Base 5 | self.abstract_class = true 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::Version < Dry::CLI::Command 4 | desc "Print version" 5 | 6 | def call(**) 7 | ViteRuby.commands.print_info 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /vite_rails/lib/vite_rails.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | 5 | require "vite_rails/version" 6 | require "vite_rails/config" 7 | require "vite_rails/tag_helpers" 8 | require "vite_rails/engine" if defined?(Rails) 9 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rake/testtask" 4 | 5 | Rake::TestTask.new do |t| 6 | t.libs << "test" 7 | t.test_files = FileList["test/**/*_test.rb"] 8 | t.verbose = true 9 | end 10 | 11 | task default: :test 12 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/.components: -------------------------------------------------------------------------------- 1 | --- 2 | :orm: none 3 | :test: rspec 4 | :mock: none 5 | :script: none 6 | :renderer: haml 7 | :stylesheet: none 8 | :namespace: BlogTutorial 9 | :migration_format: number 10 | :admin_renderer: none 11 | -------------------------------------------------------------------------------- /examples/rails/app/views/home/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 |
6 |
7 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # Add new mime types for use in respond_to blocks: 5 | # Mime::Type.register "text/richtext", :rtf 6 | -------------------------------------------------------------------------------- /vite_plugin_legacy/lib/vite_plugin_legacy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | 5 | require "vite_plugin_legacy/version" 6 | require "vite_plugin_legacy/tag_helpers" 7 | require "vite_plugin_legacy/engine" if defined?(Rails) 8 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | 3 | begin 4 | require 'rspec/core/rake_task' 5 | RSpec::Core::RakeTask.new(:spec) 6 | task default: :spec 7 | rescue LoadError 8 | end 9 | require 'vite_hanami' 10 | ViteRuby.install_tasks 11 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/entrypoints/app.css: -------------------------------------------------------------------------------- 1 | #app { 2 | font-family: Avenir, Helvetica, Arial, sans-serif; 3 | -webkit-font-smoothing: antialiased; 4 | -moz-osx-font-smoothing: grayscale; 5 | color: #2c3e50; 6 | margin-top: 30px; 7 | } 8 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/entrypoints/app.css: -------------------------------------------------------------------------------- 1 | #app { 2 | font-family: Avenir, Helvetica, Arial, sans-serif; 3 | -webkit-font-smoothing: antialiased; 4 | -moz-osx-font-smoothing: grayscale; 5 | color: #2c3e50; 6 | margin-top: 30px; 7 | } 8 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.env.test: -------------------------------------------------------------------------------- 1 | # Define ENV variables for test environment 2 | DATABASE_URL="sqlite://db/hanami_bookshelf_test.sqlite" 3 | SERVE_STATIC_ASSETS="true" 4 | WEB_SESSIONS_SECRET="e174d64924dedd5b83e2e24d5e7951bd8a1fa22be3a4502ebc36d38c39e2aa0d" 5 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | log/**/* 3 | tmp/**/* 4 | vendor/gems/* 5 | !vendor/gems/cache/ 6 | .sass-cache/* 7 | db/*.db 8 | .*.sw* 9 | 10 | # Vite Ruby 11 | /public/vite* 12 | node_modules 13 | *.local 14 | .DS_Store 15 | 16 | -------------------------------------------------------------------------------- /examples/rails/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: blog_production 11 | -------------------------------------------------------------------------------- /vite-plugin-rails/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { defineConfig } from 'vite' 3 | 4 | export default defineConfig({ 5 | resolve: { 6 | alias: { 7 | '@plugin': resolve(__dirname, 'src'), 8 | }, 9 | }, 10 | }) 11 | -------------------------------------------------------------------------------- /vite-plugin-ruby/vitest.config.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { defineConfig } from 'vite' 3 | 4 | export default defineConfig({ 5 | resolve: { 6 | alias: { 7 | '@plugin': resolve(__dirname, 'src'), 8 | }, 9 | }, 10 | }) 11 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/templates/dashboard/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 |
Vite
5 |
Hanami
6 |

7 |
8 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rake' 4 | gem 'haml' 5 | gem 'puma' 6 | gem 'padrino', '0.15.0' 7 | gem 'vite_padrino', path: '../../vite_padrino' 8 | gem 'vite_ruby', path: '../../vite_ruby' 9 | gem 'pry-byebug' 10 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/frontend/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | import { startTimer } from '~/timer' 2 | 3 | document.addEventListener('DOMContentLoaded', () => { 4 | console.log('Vite ⚡️ Rails: Engine') 5 | startTimer(document.getElementById('timer')) 6 | }) 7 | -------------------------------------------------------------------------------- /bin/snapshot: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | cd vite-plugin-ruby 6 | 7 | pnpm install 8 | pnpm build 9 | pnpm example:build 10 | 11 | rm -Rf ../test/test_app/public/vite-production 12 | cp -R example/public/vite ../test/test_app/public/vite-production 13 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "license": "MIT", 4 | "type": "module", 5 | "devDependencies": { 6 | "ci": "^2.0.0", 7 | "ni": "^0.0.2", 8 | "vite": "^6.2.6", 9 | "vite-plugin-ruby": "^5.1.1" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/.env.development: -------------------------------------------------------------------------------- 1 | # Define ENV variables for development environment 2 | DATABASE_URL="sqlite://db/hanami_bookshelf_development.sqlite" 3 | SERVE_STATIC_ASSETS="true" 4 | WEB_SESSIONS_SECRET="c93f602a5934728947857170002a5cbc91ac0af2eae09f3678b093801b0f322c" 5 | -------------------------------------------------------------------------------- /examples/rails/spec/features/admin/home_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.feature 'Admin' do 4 | before { visit(urls.administrator_path) } 5 | 6 | scenario 'visit admin page' do 7 | expect(page).to have_content('Rails Engine') 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/config.ru: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rackup 2 | # encoding: utf-8 3 | 4 | # This file can be used to start Padrino, 5 | # just execute it from the command line. 6 | 7 | require File.expand_path("../config/boot.rb", __FILE__) 8 | 9 | run Padrino.application 10 | -------------------------------------------------------------------------------- /examples/rails/config/boot.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 4 | 5 | require 'bundler/setup' # Set up gems listed in the Gemfile. 6 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations. 7 | -------------------------------------------------------------------------------- /vite-plugin-rails/tests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-rails-tests", 3 | "private": true, 4 | "devDependencies": { 5 | "vite-plugin-rails": "workspace:*" 6 | }, 7 | "dependencies": { 8 | "execa": "^5.1.1", 9 | "fast-glob": "^3.2.11" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /vite_ruby/exe/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] 5 | 6 | require "bundler/setup" 7 | require "vite_ruby" 8 | 9 | cli = ViteRuby::CLI 10 | cli.require_framework_libraries 11 | 12 | Dry::CLI.new(cli).call 13 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby 4 | VERSION = "3.9.2" 5 | 6 | # Internal: Versions used by default when running `vite install`. 7 | DEFAULT_VITE_VERSION = "^6.2.6" 8 | DEFAULT_PLUGIN_VERSION = "^5.1.1" 9 | end 10 | -------------------------------------------------------------------------------- /examples/rails/example_engine/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | # Specify your gem's dependencies in administrator.gemspec. 5 | gemspec 6 | 7 | # To use a debugger 8 | # gem 'byebug', group: [:development, :test] 9 | -------------------------------------------------------------------------------- /examples/rails/example_engine/.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /doc/ 3 | /log/*.log 4 | /pkg/ 5 | /tmp/ 6 | .byebug_history 7 | 8 | # Vite Ruby 9 | /public/administrator-vite 10 | /public/administrator-vite-dev 11 | /public/administrator-vite-test 12 | node_modules 13 | *.local 14 | .DS_Store 15 | 16 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/config/routes.rb: -------------------------------------------------------------------------------- 1 | # Configure your routes here 2 | # See: https://guides.hanamirb.org/routing/overview 3 | # 4 | # Example: 5 | # get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] } 6 | get '/dashboard', to: 'dashboard#index' 7 | get '/', to: 'dashboard#index' 8 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Configure sensitive parameters which will be filtered from the log file. 6 | Rails.application.config.filter_parameters += [:password] 7 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/controllers/administrator/timer_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_dependency 'administrator/application_controller' 4 | 5 | module Administrator 6 | class TimerController < ApplicationController 7 | def index; end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /gemfiles/Gemfile-rails-edge: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 4 | 5 | gem 'rails', github: 'rails/rails', branch: 'main' 6 | 7 | gemspec path: '../vite_ruby' 8 | gemspec path: '../vite_rails' 9 | gemspec path: '../vite_plugin_legacy' 10 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-hanami-demo", 3 | "private": true, 4 | "engines": { 5 | "node": "15.x", 6 | "yarn": "1.x" 7 | }, 8 | "devDependencies": { 9 | "sass": "^1.35.2", 10 | "vite": "^3.0.0", 11 | "vite-plugin-ruby": "^3.0.8" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/rails/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | begin 5 | load File.expand_path('spring', __dir__) 6 | rescue LoadError => error 7 | raise unless error.message.include?('spring') 8 | end 9 | require_relative '../config/boot' 10 | require 'rake' 11 | Rake.application.run 12 | -------------------------------------------------------------------------------- /examples/rails/spec/support/urls.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Internal: Provides access to every Rails route defined in the app. 4 | class Urls 5 | include Rails.application.routes.url_helpers 6 | 7 | def default_url_options 8 | ActionMailer::Base.default_url_options 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /docs/.vitepress/theme/index.js: -------------------------------------------------------------------------------- 1 | import { VPTheme } from '@mussi/vitepress-theme' 2 | import Quote from './components/Quote.vue' 3 | 4 | import 'windi.css' 5 | import './styles/styles.css' 6 | 7 | export default { 8 | ...VPTheme, 9 | enhanceApp ({ app }) { 10 | app.component('Quote', Quote) 11 | }, 12 | } 13 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/channels/consumer.js: -------------------------------------------------------------------------------- 1 | // Action Cable provides the framework to deal with WebSockets in Rails. 2 | // You can generate new channels where WebSocket features live using the `rails generate channel` command. 3 | 4 | import { createConsumer } from "@rails/actioncable" 5 | 6 | export default createConsumer() 7 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/frontend/timer.js: -------------------------------------------------------------------------------- 1 | export function startTimer (timer, loadedAt = new Date().getTime()) { 2 | function updateTimer () { 3 | const millisEllapsed = new Date().getTime() - loadedAt 4 | timer.innerHTML = Math.floor(millisEllapsed / 1000) 5 | } 6 | 7 | setInterval(updateTimer, 200) 8 | } 9 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/views/posts/index.haml: -------------------------------------------------------------------------------- 1 | - @title = 'Vite ⚡️ Padrino' 2 | %header 3 | %h1.banner 4 | %img.logo{ src: vite_asset_path('logo.svg') } 5 | %img.logo.logo-padrino{ alt: "Logo of Padrino blog", src: "http://padrinorb.com/images/logo-6475397a.svg"}/ 6 | %span.vite Vite 7 | %span.padrino Padrino 8 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/components/Hero.jsx: -------------------------------------------------------------------------------- 1 | import Version from '~/components/Version' 2 | 3 | export default function Hero () { 4 | return <> 5 |

6 | Vite Rails 7 |

8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /examples/rails/app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/helpers/administrator/application_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | module ApplicationHelper 5 | # Override: Returns the engine assets manifest. 6 | def vite_manifest 7 | Administrator::Engine.vite_ruby.manifest 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/shims.d.ts: -------------------------------------------------------------------------------- 1 | import { defineComponent } from 'vue' 2 | 3 | declare module '*.vue' { 4 | const Component: ReturnType 5 | export default Component 6 | } 7 | 8 | declare module '*.md' { 9 | const Component: ReturnType 10 | export default Component 11 | } 12 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/shims.d.ts: -------------------------------------------------------------------------------- 1 | import { defineComponent } from 'vue' 2 | 3 | declare module '*.vue' { 4 | const Component: ReturnType 5 | export default Component 6 | } 7 | 8 | declare module '*.md' { 9 | const Component: ReturnType 10 | export default Component 11 | } 12 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/web/controllers/dashboard/index_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe Web::Controllers::Dashboard::Index, type: :action do 2 | let(:action) { described_class.new } 3 | let(:params) { Hash[] } 4 | 5 | it 'is successful' do 6 | response = action.call(params) 7 | expect(response[0]).to eq 200 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /examples/rails/example_engine/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "publicOutputDir": "administrator-vite", 5 | "watchAdditionalPaths": [] 6 | }, 7 | "development": { 8 | "autoBuild": true, 9 | "port": 3037 10 | }, 11 | "test": { 12 | "autoBuild": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build.environment] 2 | NODE_VERSION = "20" 3 | NPM_FLAGS = "--version" # uncomment if using pnpm to skip npm install 4 | 5 | [build] 6 | base = "docs/" 7 | ignore = "git diff --quiet 'HEAD^' HEAD ." 8 | publish = ".vitepress/dist" 9 | command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build" 10 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/app.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module BlogTutorial 4 | class App < Padrino::Application 5 | register Padrino::Helpers 6 | register VitePadrino 7 | enable :sessions 8 | 9 | layout :application 10 | 11 | get '/' do 12 | redirect '/posts' 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # ActiveSupport::Reloader.to_prepare do 5 | # ApplicationController.renderer.defaults.merge!( 6 | # http_host: 'example.org', 7 | # https: false 8 | # ) 9 | # end 10 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # Specify a serializer for the signed and encrypted cookie jars. 6 | # Valid options are :json, :marshal, and :hybrid. 7 | Rails.application.config.action_dispatch.cookies_serializer = :json 8 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/upgrade_packages.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::UpgradePackages < ViteRuby::CLI::Install 4 | desc "Upgrades the npm packages to the recommended versions." 5 | 6 | def call(**) 7 | say "Upgrading npm packages" 8 | install_js_packages js_dependencies.join(" ") 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /examples/rails/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | begin 5 | load File.expand_path('spring', __dir__) 6 | rescue LoadError => error 7 | raise unless error.message.include?('spring') 8 | end 9 | APP_PATH = File.expand_path('../config/application', __dir__) 10 | require_relative '../config/boot' 11 | require 'rails/commands' 12 | -------------------------------------------------------------------------------- /examples/rails/bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | APP_ROOT = File.expand_path('..', __dir__) 5 | Dir.chdir(APP_ROOT) do 6 | exec 'yarnpkg', *ARGV 7 | rescue Errno::ENOENT 8 | warn 'Yarn executable was not detected in the system.' 9 | warn 'Download Yarn at https://yarnpkg.com/en/docs/install' 10 | exit 1 11 | end 12 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/views/layouts/administrator/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Administrator 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | <%= vite_client_tag %> 8 | <%= vite_javascript_tag 'application', media: 'all' %> 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/rails/app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ApplicationJob < ActiveJob::Base 4 | # Automatically retry jobs that encountered a deadlock 5 | # retry_on ActiveRecord::Deadlocked 6 | 7 | # Most jobs are safe to ignore if the underlying records are no longer available 8 | # discard_on ActiveJob::DeserializationError 9 | end 10 | -------------------------------------------------------------------------------- /examples/rails/example_engine/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | 3 | load "rails/tasks/statistics.rake" 4 | 5 | require "bundler/gem_tasks" 6 | require "vite_ruby" 7 | 8 | ViteRuby.install_tasks 9 | ViteRuby.config.root # Ensure the engine is set as the root. 10 | 11 | APP_RAKEFILE = File.expand_path('../rails/Rakefile', __dir__) 12 | load 'rails/tasks/engine.rake' 13 | -------------------------------------------------------------------------------- /examples/rails/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite_ruby/templates/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/src/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { defineConfig } from 'vite' 3 | import windicss from 'vite-plugin-windicss' 4 | 5 | export default defineConfig({ 6 | plugins: [ 7 | windicss({ 8 | preflight: false, 9 | scan: { 10 | dirs: [resolve(__dirname, '../.vitepress/theme/components')], 11 | }, 12 | }), 13 | ], 14 | }) 15 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/integrations/honeybadger.ts: -------------------------------------------------------------------------------- 1 | import Honeybadger from '@honeybadger-io/js' 2 | 3 | if (import.meta.env.HONEYBADGER_API_KEY) { 4 | Honeybadger.configure({ 5 | apiKey: import.meta.env.HONEYBADGER_API_KEY, 6 | environment: import.meta.env.MODE, 7 | }) 8 | 9 | Honeybadger.notify('Vite Rails Demo') 10 | } 11 | 12 | export default Honeybadger 13 | -------------------------------------------------------------------------------- /test/test_app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test_app", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "private": true, 7 | "dependencies": { 8 | "left-pad": "^1.2.0" 9 | }, 10 | "devDependencies": { 11 | "ci": "^2.0.0", 12 | "right-pad": "^1.0.1", 13 | "vite": "^5.0.0", 14 | "vite-plugin-ruby": "^1.0.8" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite_rails/templates/config/rails-vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "apps/web/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 2336 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite_padrino/templates/config/padrino-vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/web/views/application_layout_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | RSpec.describe Web::Views::ApplicationLayout, type: :view do 4 | let(:layout) { Web::Views::ApplicationLayout.new({ format: :html }, "contents") } 5 | let(:rendered) { layout.render } 6 | 7 | it 'contains application name' do 8 | expect(rendered).to include('Web') 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /vite_hanami/templates/config/hanami-vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "apps/web/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite_rails_legacy/templates/config/rails-vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "watchAdditionalPaths": [] 5 | }, 6 | "development": { 7 | "autoBuild": true, 8 | "publicOutputDir": "vite-dev", 9 | "port": 3036 10 | }, 11 | "test": { 12 | "autoBuild": true, 13 | "publicOutputDir": "vite-test", 14 | "port": 3037 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/features_helper.rb: -------------------------------------------------------------------------------- 1 | # Require this file for feature tests 2 | require_relative './spec_helper' 3 | 4 | require 'capybara' 5 | require 'capybara/rspec' 6 | 7 | RSpec.configure do |config| 8 | config.include RSpec::FeatureExampleGroup 9 | 10 | config.include Capybara::DSL, feature: true 11 | config.include Capybara::RSpecMatchers, feature: true 12 | end 13 | -------------------------------------------------------------------------------- /vite-plugin-ruby/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { copyFileSync } from 'fs' 2 | import type { Options } from 'tsup' 3 | 4 | export const tsup: Options = { 5 | clean: true, 6 | dts: true, 7 | shims: true, 8 | sourcemap: true, 9 | target: 'node12', 10 | format: ['esm', 'cjs'], 11 | async onSuccess () { 12 | copyFileSync('src/dev-server-index.html', 'dist/dev-server-index.html') 13 | }, 14 | } 15 | -------------------------------------------------------------------------------- /vite_ruby/templates/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | // To see this message, follow the instructions for your Ruby framework. 2 | // 3 | // When using a plain API, perhaps it's better to generate an HTML entrypoint 4 | // and link to the scripts and stylesheets, and let Vite transform it. 5 | console.log('Vite ⚡️ Ruby') 6 | 7 | // Example: Import a stylesheet in /index.css 8 | // import '~/index.css' 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "rails" 6 | 7 | gemspec path: "./vite_ruby" 8 | gemspec path: "./vite_rails" 9 | gemspec path: "./vite_plugin_legacy" 10 | 11 | group :development, :test do 12 | gem "benchmark-ips" 13 | gem "rubocop" 14 | gem "rubocop-minitest" 15 | gem "rubocop-performance" 16 | gem "standard", require: false 17 | end 18 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/example_import.js: -------------------------------------------------------------------------------- 1 | import '~/integrations/bugsnag' 2 | // import '~/integrations/honeybadger' 3 | import React from 'react' 4 | import { createRoot } from 'react-dom/client' 5 | 6 | import Hero from '~/components/Hero.jsx' 7 | 8 | console.log('Vite ⚡️ Rails') 9 | 10 | const root = createRoot(document.getElementById('hero')) 11 | root.render(React.createElement(Hero)) 12 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/integrations/bugsnag.ts: -------------------------------------------------------------------------------- 1 | import Bugsnag from '@bugsnag/js' 2 | import BugsnagPluginReact from '@bugsnag/plugin-react' 3 | 4 | if (import.meta.env.BUGSNAG_API_KEY) { 5 | Bugsnag.start({ 6 | apiKey: import.meta.env.BUGSNAG_API_KEY, 7 | plugins: [new BugsnagPluginReact()], 8 | }) 9 | 10 | Bugsnag.notify(new Error('Test Error')) 11 | } 12 | 13 | export default Bugsnag 14 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/error.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Internal: Provides common functionality for errors. 4 | class ViteRuby::Error < StandardError 5 | def message 6 | super.sub(":troubleshooting:", <<~MSG) 7 | Visit the Troubleshooting guide for more information: 8 | https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting 9 | MSG 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/controllers/dashboard/index.rb: -------------------------------------------------------------------------------- 1 | require 'hanami/action/cache' 2 | 3 | module Web 4 | module Controllers 5 | module Dashboard 6 | class Index 7 | include Web::Action 8 | include Hanami::Action::Cache 9 | 10 | cache_control :public, max_age: 600 11 | 12 | def call(params) 13 | end 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "sourceCodeDir": "app/frontend", 4 | "ssrBuildEnabled": true, 5 | "watchAdditionalPaths": [] 6 | }, 7 | "development": { 8 | "autoBuild": true, 9 | "publicOutputDir": "vite-dev", 10 | "port": 3036 11 | }, 12 | "test": { 13 | "autoBuild": true, 14 | "publicOutputDir": "vite-test", 15 | "port": 3037 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /vite_rails_legacy/lib/vite_rails_legacy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | 5 | require "vite_rails_legacy/version" 6 | require "vite_rails_legacy/config" 7 | require "vite_rails_legacy/tag_helpers" 8 | require "vite_rails_legacy/engine" if defined?(Rails) 9 | 10 | # Active Support 4 does not support multiple arguments in append. 11 | class Array 12 | alias_method :append, :push 13 | end 14 | -------------------------------------------------------------------------------- /test/mode_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | class ModeTest < ViteRuby::Test 6 | def test_mode 7 | assert_equal Rails.env, ViteRuby.config.mode 8 | assert_equal ViteRuby.config.mode, ViteRuby.mode 9 | end 10 | 11 | def test_mode_with_rails_env 12 | with_rails_env("staging") do |config| 13 | assert_equal "staging", config.mode 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/test_app/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "development": { 3 | "autoBuild": true, 4 | "port": "3535", 5 | "https": true, 6 | "publicOutputDir": "vite-dev" 7 | }, 8 | "test": { 9 | "autoBuild": true, 10 | "publicOutputDir": "vite-test" 11 | }, 12 | "production": { 13 | "publicOutputDir": "vite-production" 14 | }, 15 | "staging": { 16 | "publicOutputDir": "vite-staging" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "target": "esnext", 5 | "moduleResolution": "node", 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true, 8 | "allowJs": true, 9 | "strict": true, 10 | "baseUrl": ".", 11 | "paths": { 12 | "/@theme/*": [".vitepress/theme/*"] 13 | } 14 | }, 15 | "include": ["env.d.ts", "src/**/*", ".vitepress/**/*"] 16 | } 17 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/styles/theme.css: -------------------------------------------------------------------------------- 1 | .hero > span { 2 | transition: all 0.3s ease; 3 | letter-spacing: -0.025em; 4 | text-shadow: 1px 1px 2px #00000063; 5 | } 6 | 7 | .logo { 8 | transition: all 0.3s ease; 9 | opacity: 1; 10 | height: clamp(6rem, 20vw, 8rem); 11 | margin: 0 auto 1.5rem; 12 | } 13 | 14 | .hanami { 15 | color: #8E43E8; 16 | } 17 | 18 | .vite { 19 | color: #ffac33; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "target": "es2017", 5 | "lib": ["ESNext", "DOM"], 6 | "esModuleInterop": true, 7 | "strict": true, 8 | "strictNullChecks": true, 9 | "moduleResolution": "Node", 10 | "resolveJsonModule": true, 11 | "skipLibCheck": true 12 | }, 13 | "exclude": [ 14 | "**/dist", 15 | "**/node_modules", 16 | "**/test" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/dev.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::Dev < ViteRuby::CLI::Vite 4 | DEFAULT_ENV = CURRENT_ENV || "development" 5 | 6 | desc "Start the Vite development server." 7 | shared_options 8 | option(:force, desc: "Force Vite to re-bundle dependencies", type: :boolean) 9 | 10 | def call(**options) 11 | super { |args| ViteRuby.run(args, exec: true) } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/missing_executable_error.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Internal: Raised when the Vite executable can not be found. 4 | class ViteRuby::MissingExecutableError < ViteRuby::Error 5 | def initialize(error = nil) 6 | super <<~MSG 7 | ❌ The vite binary is not available. Have you installed the npm packages? 8 | 9 | :troubleshooting: 10 | #{error} 11 | MSG 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/components/Version.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default function Version () { 4 | const url = `https://github.com/ElMassimo/vite_ruby/tree/${import.meta.env.HEROKU_SLUG_COMMIT}/examples/rails` 5 | return <> 6 | 7 | { import.meta.env.HEROKU_RELEASE_VERSION } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /examples/rails/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # This file should contain all the record creation needed to seed the database with its default values. 3 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 4 | # 5 | # Examples: 6 | # 7 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 8 | # Character.create(name: 'Luke', movie: movies.first) 9 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { defineConfig } from 'vite' 3 | import Vue from '@vitejs/plugin-vue' 4 | import ViteRails from 'vite-plugin-rails' 5 | 6 | export default defineConfig({ 7 | resolve: { 8 | alias: { 9 | '@assets/': `${resolve(__dirname, 'app/assets')}/`, 10 | }, 11 | }, 12 | plugins: [ 13 | Vue(), 14 | ViteRails({ fullReload: false }), 15 | ], 16 | }) 17 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/templates/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Web 5 | <%= favicon %> 6 | <%= vite_client %> 7 | 8 | <%= vite_stylesheet 'styles.scss' %> 9 | <%= vite_typescript 'application' %> 10 | 11 | 12 | 13 | 14 | <%= yield %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /vite-plugin-rails/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "target": "es2017", 5 | "lib": ["ESNext", "DOM"], 6 | "esModuleInterop": true, 7 | "strict": true, 8 | "strictNullChecks": true, 9 | "moduleResolution": "Node", 10 | "resolveJsonModule": true, 11 | "skipLibCheck": true, 12 | }, 13 | "exclude": [ 14 | "**/dist", 15 | "**/node_modules", 16 | "**/test" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /vite-plugin-ruby/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ESNext", 4 | "target": "es2017", 5 | "lib": ["ESNext", "DOM"], 6 | "esModuleInterop": true, 7 | "strict": true, 8 | "strictNullChecks": true, 9 | "moduleResolution": "Node", 10 | "resolveJsonModule": true, 11 | "skipLibCheck": true, 12 | }, 13 | "exclude": [ 14 | "**/dist", 15 | "**/node_modules", 16 | "**/test" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/config/apps.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | Padrino.configure_apps do 4 | # enable :sessions 5 | set :session_secret, '592d4263c8634b39fc482553b4b60db29c9de5eb46e730eff33856599c41e480' 6 | set :protection, except: :path_traversal 7 | set :protect_from_csrf, true 8 | end 9 | 10 | # Mounts the core application for this project 11 | Padrino.mount('BlogTutorial::App', app_file: Padrino.root('app/app.rb')).to('/') 12 | -------------------------------------------------------------------------------- /docs/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | declare module '@mussi/vitepress-theme/config' { 5 | import { UserConfig } from 'vitepress' 6 | const config: () => Promise 7 | export default config 8 | } 9 | 10 | declare module '@mussi/vitepress-theme/highlight' { 11 | const createHighlighter: () => Promise<(input: string) => string> 12 | export default createHighlighter 13 | } 14 | -------------------------------------------------------------------------------- /test/leading_slash_benchmark.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "benchmark/ips" 4 | require "bundler/setup" 5 | 6 | REGEX = %r{^/} 7 | 8 | Benchmark.ips do |x| 9 | x.config(time: 3, warmup: 1) 10 | 11 | path = "/application.ts" 12 | 13 | x.report("start_with? [1..-1]") { path.start_with?("/") ? path[1..] : path } 14 | x.report("sub %r{^/}") { path.sub(%r{^/}, "") } 15 | x.report("sub REGEX") { path.sub(REGEX, "") } 16 | x.compare! 17 | end 18 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/spec/web/views/dashboard/index_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe Web::Views::Dashboard::Index, type: :view do 2 | let(:exposures) { Hash[format: :html] } 3 | let(:template) { Hanami::View::Template.new('apps/web/templates/dashboard/index.html.erb') } 4 | let(:view) { described_class.new(template, exposures) } 5 | let(:rendered) { view.render } 6 | 7 | it 'exposes #format' do 8 | expect(view.format).to eq exposures.fetch(:format) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /vite_plugin_legacy/lib/vite_plugin_legacy/engine.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rails/railtie" 4 | 5 | class VitePluginLegacy::Engine < Rails::Engine 6 | initializer "vite_plugin_legacy.helper" do 7 | ActiveSupport.on_load(:action_controller) do 8 | ActionController::Base.helper(VitePluginLegacy::TagHelpers) 9 | end 10 | 11 | ActiveSupport.on_load(:action_view) do 12 | include VitePluginLegacy::TagHelpers 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /examples/rails/config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | 4uQ/FTEUk7w8HkqXJTybTidsDrt/0S68h4/Qkyi/JQWhFGc0mov2XuhPNO5uHerSzuZHPZrhI4ypkgNHzLEVw0tXsCjbM36iNcwa2Th/hMOVDcDx32fl0lSIGZMji+thvtXqQUe8/+ouMd/DSdsnq9+8//2HeuhoL7kxAvFLlukh69iXsXgbrLa+Sctt3cbbVPqRxdjTuLs1uIsEV5IHJohdqR0xWIgpIz4ain5A7UD36cpJZrJFXNKrNIs9i5IsjffoDuXOSy3nClgHU4UxBu09FkQ/Jd4eBBau0bVHUYtDbZTQdFlsK/6SYW4DPjPJ6YOtz8TZXDIloO8jZlwvGpJIXC8NAMowrWleXVyxE69+VTg99cyjCClw15RlQ1OvpfzIsz6PwwhcorlVmfPV41qP1kXZDuq5YUVx--lcdafa0m0RVjD1vK--UH6p5ugXTKfdoxO41haMGA== -------------------------------------------------------------------------------- /vite-plugin-rails/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["."], 3 | "exclude": ["**/dist/**"], 4 | "compilerOptions": { 5 | "target": "esnext", 6 | "module": "esnext", 7 | "outDir": "dist", 8 | "allowJs": true, 9 | "esModuleInterop": true, 10 | "moduleResolution": "node", 11 | "baseUrl": ".", 12 | "jsx": "preserve", 13 | "types": ["vite/client", "vitest", "node"], 14 | "paths": { 15 | "@plugin/*": ["../src/*"] 16 | }, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vite-plugin-ruby/tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["."], 3 | "exclude": ["**/dist/**"], 4 | "compilerOptions": { 5 | "target": "esnext", 6 | "module": "esnext", 7 | "outDir": "dist", 8 | "allowJs": true, 9 | "esModuleInterop": true, 10 | "moduleResolution": "node", 11 | "baseUrl": ".", 12 | "jsx": "preserve", 13 | "types": ["vite/client", "vitest", "node"], 14 | "paths": { 15 | "@plugin/*": ["../src/*"] 16 | }, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /test/test_app/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Vite ⚡️ Ruby 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | <%= vite_client_tag %> 8 | 9 | 10 | 11 | <%= vite_stylesheet_tag 'styles' %> 12 | <%= vite_typescript_tag 'application' %> 13 | 14 | 15 | 16 | <%= yield %> 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 5 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 6 | 7 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 8 | # Rails.backtrace_cleaner.remove_silencers! 9 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/styles/theme.css: -------------------------------------------------------------------------------- 1 | .smooth { 2 | @apply transition-all duration-300 text-shadow; 3 | } 4 | 5 | .hero > span { 6 | letter-spacing: -0.025em; 7 | text-shadow: 1px 1px 2px #00000063; 8 | } 9 | 10 | .logo { 11 | opacity: 1; 12 | height: clamp(6rem, 20vw, 8rem); 13 | margin: 0 auto 1.5rem; 14 | } 15 | 16 | .rails { 17 | color: #cc0000; 18 | } 19 | 20 | .vite { 21 | color: #ffac33; 22 | } 23 | 24 | .logo-bg { 25 | background-image: url("~/images/logo.png"); 26 | } 27 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Vite ⚡️ Ruby 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | <%= vite_client_tag %> 8 | 9 | 10 | 11 | <%= vite_stylesheet_tag 'styles' %> 12 | <%= vite_typescript_tag 'application' %> 13 | 14 | 15 | 16 | <%= yield %> 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/frontend/styles/theme.css: -------------------------------------------------------------------------------- 1 | .banner > span { 2 | transition: all 0.3s ease; 3 | letter-spacing: -0.025em; 4 | text-shadow: 1px 1px 2px #00000063; 5 | } 6 | 7 | .logo.logo { 8 | transition: all 0.3s ease; 9 | opacity: 1; 10 | height: clamp(6rem, 20vw, 8rem); 11 | margin: 0 auto 1.5rem; 12 | } 13 | 14 | .logo.logo-padrino { 15 | height: clamp(5rem, 15vw, 7rem); 16 | } 17 | 18 | .padrino { 19 | color: black; 20 | } 21 | 22 | .vite { 23 | color: #ffac33; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/clobber.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::Clobber < Dry::CLI::Command 4 | desc "Clear the Vite cache, temp files, and builds" 5 | 6 | current_env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development" 7 | 8 | option(:mode, default: current_env, values: %w[development production test], aliases: ["m"], desc: "The mode to use") 9 | 10 | def call(mode:, **) 11 | ViteRuby.env["VITE_RUBY_MODE"] = mode 12 | ViteRuby.commands.clobber 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /.github/workflows/rubocop.yml: -------------------------------------------------------------------------------- 1 | name: Rubocop 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: Rubocop 8 | runs-on: ${{ matrix.os }} 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest] 12 | ruby: [ 13 | 3.3 14 | ] 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - uses: ruby/setup-ruby@v1 20 | with: 21 | ruby-version: ${{ matrix.ruby }} 22 | bundler-cache: true 23 | 24 | - name: Rubocop 25 | run: bin/rubocop 26 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "action_controller/railtie" 4 | require "action_view/railtie" 5 | 6 | if RUBY_VERSION.start_with?("2.4") 7 | require "vite_rails_legacy" 8 | ViteRails = ViteRailsLegacy 9 | else 10 | require "vite_rails" 11 | end 12 | 13 | module TestDummyApp 14 | class Application < Rails::Application 15 | config.load_defaults Rails::VERSION::STRING.to_f 16 | config.secret_key_base = SecureRandom.hex 17 | config.eager_load = true 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { resolve } from 'path' 2 | import { defineConfig } from 'vite' 3 | import Vue from '@vitejs/plugin-vue' 4 | import ViteRuby from 'vite-plugin-ruby' 5 | import ViteLegacy from '@vitejs/plugin-legacy' 6 | 7 | export default defineConfig({ 8 | resolve: { 9 | alias: { 10 | '@assets/': `${resolve(__dirname, 'app/assets')}/`, 11 | }, 12 | }, 13 | plugins: [ 14 | Vue(), 15 | ViteRuby(), 16 | ViteLegacy({ 17 | targets: ['defaults', 'not IE 11'], 18 | }), 19 | ], 20 | }) 21 | -------------------------------------------------------------------------------- /vite_rails/lib/vite_rails/config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ViteRails::Config 4 | private 5 | 6 | # Override: Default values for a Rails application. 7 | def config_defaults 8 | require "rails" 9 | asset_host = Rails.application&.config&.action_controller&.asset_host 10 | super( 11 | asset_host: asset_host.is_a?(Proc) ? nil : asset_host, 12 | mode: Rails.env.to_s, 13 | root: Rails.root || Dir.pwd, 14 | ) 15 | end 16 | end 17 | 18 | ViteRuby::Config.singleton_class.prepend(ViteRails::Config) 19 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite App 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/rails/plugins/bugsnag.ts: -------------------------------------------------------------------------------- 1 | import { BugsnagBuildReporterPlugin, BugsnagSourceMapUploaderPlugin } from 'vite-plugin-bugsnag' 2 | 3 | const options = { 4 | apiKey: process.env.BUGSNAG_API_KEY!, 5 | appVersion: process.env.HEROKU_RELEASE_VERSION!, 6 | } 7 | 8 | const useBugsnag = process.env.RAILS_ENV === 'production' && Boolean(options.apiKey) 9 | 10 | export default useBugsnag 11 | ? [ 12 | BugsnagBuildReporterPlugin({ ...options, releaseStage: process.env.RAILS_ENV }), 13 | BugsnagSourceMapUploaderPlugin({ ...options, overwrite: true }), 14 | ] 15 | : [] 16 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite App 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/styles.scss: -------------------------------------------------------------------------------- 1 | @import '../styles/logo.scss'; 2 | 3 | @media (prefers-color-scheme: dark) { 4 | html, body { 5 | background: black; 6 | } 7 | 8 | .version { 9 | color: white; 10 | } 11 | } 12 | 13 | header { 14 | display: grid; 15 | height: 100vh; 16 | margin: 0 auto; 17 | padding-bottom: 20vh; 18 | place-content: center; 19 | } 20 | 21 | .hero { 22 | box-sizing: border-box; 23 | font-size: clamp(4rem, 10vw, 4.5rem); 24 | line-height: 1; 25 | font-weight: 800; 26 | margin: 0 0 0 1rem; 27 | text-align: center; 28 | } 29 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "additionalEntrypoints": [ 4 | "~/{assets,fonts,icons,images}/**/*", 5 | "~/index.html", 6 | "app/assets/*.{css,js,png}" 7 | ], 8 | "watchAdditionalPaths": [ 9 | "app/assets/**/*" 10 | ] 11 | }, 12 | "development": { 13 | "autoBuild": true, 14 | "publicOutputDir": "vite-dev", 15 | "port": 3037 16 | }, 17 | "test": { 18 | "autoBuild": true, 19 | "publicOutputDir": "vite-test", 20 | "port": 3037 21 | }, 22 | "production": { 23 | "base": "/nested" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/config/vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "all": { 3 | "additionalEntrypoints": [ 4 | "~/{assets,fonts,icons,images}/**/*", 5 | "~/index.html", 6 | "app/assets/*.{css,js,png}" 7 | ], 8 | "watchAdditionalPaths": [ 9 | "app/assets/**/*" 10 | ] 11 | }, 12 | "development": { 13 | "autoBuild": true, 14 | "publicOutputDir": "vite-dev", 15 | "port": 3037 16 | }, 17 | "test": { 18 | "autoBuild": true, 19 | "publicOutputDir": "vite-test", 20 | "port": 3037 21 | }, 22 | "production": { 23 | "base": "/nested" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vite_rails_legacy/lib/vite_rails_legacy/config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module ViteRailsLegacy::Config 4 | # Override: Default values for a Rails application. 5 | def config_defaults 6 | require "rails" 7 | asset_host = Rails.application&.config&.action_controller&.asset_host 8 | super( 9 | asset_host: asset_host.is_a?(Proc) ? nil : asset_host, 10 | mode: Rails.env.to_s, 11 | root: Rails.root || Dir.pwd, 12 | ) 13 | end 14 | end 15 | 16 | require "active_support/core_ext/hash" 17 | ViteRuby::Config.singleton_class.prepend(ViteRailsLegacy::Config) 18 | -------------------------------------------------------------------------------- /examples/rails/Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Add your own tasks in files placed in lib/tasks ending in .rake, 4 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 5 | 6 | require_relative 'config/application' 7 | 8 | Rails.application.load_tasks 9 | 10 | Rake::Task['assets:precompile'].enhance do |task| 11 | Dir.chdir(Rails.root.join('example_engine')) { 12 | _, stderr, status = ViteRuby::IO.capture("VITE_RUBY_VITE_BIN_PATH=#{Rails.root.join(ViteRuby.config.vite_bin_path)} bin/vite build") 13 | raise stderr unless status 14 | } 15 | end 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Troubleshooting & FAQs 4 | url: https://vite-ruby.netlify.app/guide/troubleshooting.html 5 | about: 'Please check the most common configuration problems before opening an issue' 6 | - name: Discord Chat 7 | url: https://chat.vitejs.dev 8 | about: 'Ask questions and discuss with other users in real time in the #rails channel' 9 | - name: Questions & Discussions 10 | url: https://github.com/ElMassimo/vite_ruby/discussions 11 | about: Use GitHub discussions for message-board style questions and discussions. 12 | -------------------------------------------------------------------------------- /examples/rails/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # This file loads Spring without using Bundler, in order to be fast. 5 | # It gets overwritten when you run the `spring binstub` command. 6 | 7 | unless defined?(Spring) 8 | require 'rubygems' 9 | require 'bundler' 10 | 11 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 12 | spring = lockfile.specs.detect { |spec| spec.name == 'spring' } 13 | if spring 14 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 15 | gem 'spring', spring.version 16 | require 'spring/binstub' 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Be sure to restart your server when you modify this file. 4 | 5 | # This file contains settings for ActionController::ParamsWrapper which 6 | # is enabled by default. 7 | 8 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 9 | ActiveSupport.on_load(:action_controller) do 10 | wrap_parameters format: [:json] 11 | end 12 | 13 | # To enable root element in JSON for ActiveRecord objects. 14 | # ActiveSupport.on_load(:active_record) do 15 | # self.include_root_in_json = true 16 | # end 17 | -------------------------------------------------------------------------------- /docs/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page: true 3 | sidebar: false 4 | features: 5 | - title: 🔥 Fast Server Start 6 | details: Unlike Webpacker, files are processed on demand! 7 | link: /motivation.html#webpack—increasing-load-times 8 | - title: ⚡️ Instant Changes 9 | details: Fast updates thanks to HMR. Goodbye full-page reloads! 10 | link: /guide/introduction.html#why-vite-🤔 11 | - title: 🚀 Zero-Config Deploys 12 | details: Integrates with Rake asset management tasks. 13 | link: /guide/deployment.html 14 | --- 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /examples/rails/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Vite ⚡️ Rails 5 | <%= csrf_meta_tags %> 6 | <%= csp_meta_tag %> 7 | <%= vite_client_tag %> 8 | <%= vite_react_refresh_tag %> 9 | 10 | 11 | 12 | <%= vite_stylesheet_tag 'styles.scss' %> 13 | <%= vite_typescript_tag 'application', 'data-turbo-track': 'reload', media: 'all' %> 14 | 15 | 16 | 17 | <%= yield %> 18 | <%= vite_legacy_typescript_tag 'application' %> 19 | 20 | 21 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/ssr/ssr.ts: -------------------------------------------------------------------------------- 1 | import { createSSRApp, h } from 'vue' 2 | import { renderToString } from '@vue/server-renderer' 3 | import { createInertiaApp } from '@inertiajs/inertia-vue3' 4 | import createServer from '@inertiajs/server' 5 | 6 | const pages = import.meta.glob('../pages/*.vue', { import: 'default', eager: true }) 7 | 8 | createServer(page => createInertiaApp({ 9 | page, 10 | render: renderToString, 11 | resolve: name => pages[`../Pages/${name}.vue`], 12 | setup ({ app, props, plugin }) { 13 | return createSSRApp({ 14 | render: () => h(app, props), 15 | }).use(plugin) 16 | }, 17 | })) 18 | -------------------------------------------------------------------------------- /examples/rails/test_helpers/base_test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class BaseTestHelper < Capybara::TestHelper 4 | # Aliases: Semantic aliases for locators, can be used in most DSL methods. 5 | aliases( 6 | # Avoid defining :el here since it will be inherited by all helpers. 7 | ) 8 | 9 | # Finders: A convenient way to get related data or nested elements. 10 | 11 | # Actions: Encapsulate complex actions to provide a cleaner interface. 12 | 13 | # Assertions: Check on element properties, used with `should` and `should_not`. 14 | 15 | # Background: Helpers to add/modify/delete data in the database or session. 16 | end 17 | -------------------------------------------------------------------------------- /docs/.vitepress/theme/components/Quote.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/app/frontend/App.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 17 | 18 | 26 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/App.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 21 | 22 | 26 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "vitepress dev --port 3005 --open", 5 | "build": "vitepress build", 6 | "preview": "vitepress serve --port 5050 --open", 7 | "now": "npm run build && npm run preview" 8 | }, 9 | "dependencies": { 10 | "@mussi/vitepress-theme": "^1.0.2", 11 | "vite-plugin-windicss": "^1.8.3", 12 | "vitepress": "^0.22.3", 13 | "vue": "^3.2.31" 14 | }, 15 | "pnpm": { 16 | "peerDependencyRules": { 17 | "ignoreMissing": [ 18 | "@algolia/client-search", 19 | "react", 20 | "react-dom", 21 | "@types/react" 22 | ] 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/file_operations_benchmark.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "benchmark/ips" 4 | require "bundler/setup" 5 | 6 | Benchmark.ips do |x| 7 | x.config(time: 3, warmup: 1) 8 | 9 | dir = Pathname.new(__dir__).join("..") 10 | 11 | x.report("Pathname#file?") { dir.join("Gemfile").file? } 12 | x.report("Pathname#exist?") { dir.join("Gemfile").exist? } 13 | x.report("File.exist?") { File.exist?("#{dir}/Gemfile") } 14 | x.report("File.file?") { File.file?("#{dir}/Gemfile") } 15 | x.report("File.exist? w/join") { File.exist?(dir.join("Gemfile")) } 16 | x.report("File.file? w/join") { File.file?(dir.join("Gemfile")) } 17 | 18 | x.compare! 19 | end 20 | -------------------------------------------------------------------------------- /vite_padrino/lib/vite_padrino.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_ruby" 4 | require "vite_padrino/version" 5 | require "vite_padrino/tag_helpers" 6 | 7 | module VitePadrino 8 | # Internal: Called when the Rack app is available. 9 | def self.registered(app) 10 | if RACK_ENV != "production" && ViteRuby.run_proxy? 11 | app.use(ViteRuby::DevServerProxy, ssl_verify_none: true) 12 | end 13 | ViteRuby.instance.logger = app.logger 14 | included(app) 15 | end 16 | 17 | # Internal: Called when the module is registered in the Padrino app. 18 | def self.included(base) 19 | base.send :include, VitePadrino::TagHelpers 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /examples/rails/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.0 AS builder 2 | 3 | # Install nodejs in the ruby image 4 | RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs 5 | RUN npm install -g yarn 6 | 7 | # Gems and packages will be cached in a separate image using a mounted volume. 8 | ENV BUNDLE_PATH /bundler_cache 9 | ENV YARN_CACHE_FOLDER /yarn_cache 10 | ENV BUNDLER_VERSION 2.3.22 11 | 12 | # Match the version of Bundler with that specified in Gemfile.lock 13 | RUN gem update --system \ 14 | && gem install bundler -v $BUNDLER_VERSION 15 | 16 | # Set working directory inside the image home. 17 | ENV APP_PATH /app 18 | WORKDIR $APP_PATH 19 | ADD . $APP_PATH 20 | -------------------------------------------------------------------------------- /examples/rails/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "module": "es2020", 5 | "target": "es2020", 6 | "moduleResolution": "node", 7 | "allowJs": true, 8 | "jsx": "preserve", 9 | "jsxFactory": "h", 10 | "jsxFragmentFactory": "Fragment", 11 | "strict": true, 12 | "declaration": true, 13 | "noUnusedLocals": true, 14 | "skipLibCheck": true, 15 | "esModuleInterop": true, 16 | "lib": ["ESNext", "DOM"], 17 | "paths": { 18 | "~/*": ["./app/frontend/*"], 19 | "@/*": ["./app/frontend/*"] 20 | }, 21 | }, 22 | "exclude": [ 23 | "**/dist", 24 | "**/node_modules", 25 | "**/public" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/app/frontend/ssr/ssr.ts: -------------------------------------------------------------------------------- 1 | import { createSSRApp, h } from 'vue' 2 | import { renderToString } from '@vue/server-renderer' 3 | import { createInertiaApp } from '@inertiajs/inertia-vue3' 4 | import createServer from '@inertiajs/server' 5 | import logo from '~/images/logo.svg' 6 | console.info({ logo }) 7 | 8 | const pages = import.meta.glob('../pages/*.vue', { import: 'default', eager: true }) 9 | 10 | createServer(page => createInertiaApp({ 11 | page, 12 | render: renderToString, 13 | resolve: name => pages[`../Pages/${name}.vue`], 14 | setup ({ app, props, plugin }) { 15 | return createSSRApp({ 16 | render: () => h(app, props), 17 | }).use(plugin) 18 | }, 19 | })) 20 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/build.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::Build < ViteRuby::CLI::Vite 4 | DEFAULT_ENV = CURRENT_ENV || "production" 5 | 6 | desc "Bundle all entrypoints using Vite." 7 | shared_options 8 | option(:ssr, desc: "Build the SSR entrypoint instead", type: :boolean) 9 | option(:force, desc: "Force the build even if assets have not changed", type: :boolean) 10 | option(:watch, desc: "Start the Rollup watcher and rebuild on files changes", type: :boolean) 11 | option(:profile, desc: "Gather performance metrics from the build ", type: :boolean) 12 | 13 | def call(**options) 14 | super { |args| ViteRuby.commands.build_from_task(*args) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/upgrade.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::Upgrade < ViteRuby::CLI::Install 4 | desc "Updates Vite Ruby related gems and npm packages." 5 | 6 | def call(**) 7 | upgrade_ruby_gems 8 | upgrade_npm_packages 9 | end 10 | 11 | protected 12 | 13 | def upgrade_ruby_gems 14 | say "Updating gems" 15 | 16 | libraries = ViteRuby.framework_libraries.map { |_f, library| library.name } 17 | 18 | run_with_capture("bundle update #{libraries.join(" ")}") 19 | end 20 | 21 | # NOTE: Spawn a new process so that it uses the updated vite_ruby. 22 | def upgrade_npm_packages 23 | Kernel.exec("bundle exec vite upgrade_packages") 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/test_app/.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /pkg 3 | log 4 | tmp 5 | node_modules 6 | .byebug_history 7 | yarn-debug.log* 8 | yarn-error.log* 9 | .yarn-integrity 10 | gemfiles/*.lock 11 | .DS_Store 12 | 13 | # Vite on Rails 14 | /public/vite* 15 | test/test_app/public/vite-production 16 | node_modules 17 | *.local 18 | .DS_Store 19 | 20 | # Vitepress 21 | dist 22 | examples_dist 23 | node_modules 24 | coverage 25 | .nyc_output 26 | .rpt2_cache 27 | .env 28 | local.log 29 | .DS_Store 30 | e2e/reports 31 | e2e/screenshots 32 | __build__ 33 | playground_dist 34 | yarn-error.log 35 | temp 36 | markdown 37 | explorations 38 | selenium-server.log 39 | 40 | # Algolia 41 | .algolia.env 42 | 43 | # Hanami 44 | .env.local 45 | .env.*.local 46 | -------------------------------------------------------------------------------- /test/test_app/app/frontend/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | // To see this message, add the following to the `` section in your 2 | // views/layouts/application.html.erb 3 | // 4 | // <%= vite_client_tag %> 5 | // <%= vite_javascript_tag 'application' %> 6 | console.log('Vite ⚡️ Rails') 7 | 8 | // Example: Load Rails libraries in Vite. 9 | // 10 | // import * as Turbo from '@hotwired/turbo' 11 | // Turbo.start() 12 | // 13 | // import ActiveStorage from '@rails/activestorage' 14 | // ActiveStorage.start() 15 | // 16 | // // Import all channels. 17 | // const channels = import.meta.glob('./**/*_channel.js', { eager: true }) 18 | 19 | // Example: Import a stylesheet in app/frontend/index.css 20 | // import '~/index.css' 21 | -------------------------------------------------------------------------------- /vite-plugin-rails/scripts/postbuild.mjs: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import path from 'path' 3 | import { fileURLToPath } from 'url' 4 | 5 | // Note: Once TypeScript 4.5 is out of beta we can drop the whole script. 6 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 7 | 8 | const file = path.join(__dirname, '..', 'dist', 'index.cjs') 9 | const source = fs.readFileSync(file, 'utf-8') 10 | const code = source.replaceAll( 11 | 'isNodeMode || !mod || !mod.__esModule', 12 | '!mod.default', 13 | ) 14 | 15 | if (code !== source) { 16 | console.info(`Writing ${file}`) 17 | fs.writeFileSync(file, code) 18 | } 19 | else { 20 | const message = 'Did not find CJS pattern to replace.' 21 | console.warn(message) 22 | } 23 | -------------------------------------------------------------------------------- /docs/.stylelintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | 'stylelint-config-standard', 4 | ], 5 | plugins: [ 6 | 'stylelint-order', 7 | ], 8 | rules: { 9 | 'no-descending-specificity': null, 10 | 'no-empty-source': null, 11 | 'property-case': null, 12 | 'order/properties-order': [ 13 | ['composes'], 14 | { unspecified: 'bottomAlphabetical' }, 15 | ], 16 | 'order/order': [ 17 | 'at-rules', 18 | 'custom-properties', 19 | 'declarations', 20 | ], 21 | 'order/properties-alphabetical-order': true, 22 | 'selector-pseudo-element-no-unknown': [ 23 | true, 24 | { 25 | ignorePseudoElements: ['v-deep'], 26 | }, 27 | ], 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/views/layouts/application.haml: -------------------------------------------------------------------------------- 1 | !!! Strict 2 | %html 3 | %head 4 | %title= "Padrino Sample Blog" 5 | = vite_client_tag 6 | = vite_stylesheet_tag 'styles' 7 | = vite_javascript_tag 'application' 8 | 9 | %body 10 | %nav.navbar 11 | %div.container 12 | .navbar-brand 13 | %a.navbar-item{:href => "/"} 14 | %img{:alt => "Logo of Padrino blog", :src => "http://padrinorb.com/images/logo-6475397a.svg"}/ 15 | %span.navbar-burger.burger{"data-target" => "navbarMenu"} 16 | %span 17 | %span 18 | %span 19 | #navbarMenu.navbar-menu 20 | .navbar-end 21 | %div.container 22 | #main= yield 23 | -------------------------------------------------------------------------------- /examples/rails/config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: postgresql 3 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 4 | host: <%= ENV.fetch("DB_HOST", "localhost") %> 5 | user: <%= ENV.fetch("DB_USER", "") %> 6 | password: <%= ENV.fetch("DB_PASSWORD", "") %> 7 | timeout: 5000 8 | 9 | development: 10 | <<: *default 11 | database: vite_rails_blog_development 12 | 13 | # Warning: The database defined as "test" will be erased and 14 | # re-generated from your development database when you run "rake". 15 | # Do not set this db to the same as development or production. 16 | test: 17 | <<: *default 18 | database: vite_rails_blog_test 19 | 20 | production: 21 | <<: *default 22 | database: vite_rails_blog 23 | -------------------------------------------------------------------------------- /examples/rails/spec/features/home_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.feature 'Home', test_helpers: [:home] do 4 | before { visit(urls.home_path) } 5 | 6 | scenario 'visit home page' do 7 | home.should.have_content('Vite Rails') 8 | end 9 | 10 | scenario 'hmr in the home page when the Vite dev server is running', if: !ENV['CI'] do 11 | raise 'the Vite dev server is not running' unless ViteRuby.instance.dev_server_running? 12 | 13 | home.should.have_content('Vite Rails') 14 | 15 | home.rewrite('Rails', to: 'Ruby') 16 | home.should_now.have_content('Vite Ruby') 17 | 18 | home.rewrite('Ruby', to: 'Rails') 19 | home.should_now.have_content('Vite Rails') 20 | ensure 21 | home.revert_changes 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/README.md: -------------------------------------------------------------------------------- 1 | # Hanami Bookshelf 2 | 3 | Welcome to your new Hanami project! 4 | 5 | ## Setup 6 | 7 | How to run tests: 8 | 9 | ``` 10 | % bundle exec rake 11 | ``` 12 | 13 | How to run the development console: 14 | 15 | ``` 16 | % bundle exec hanami console 17 | ``` 18 | 19 | How to run the development server: 20 | 21 | ``` 22 | % bundle exec hanami server 23 | ``` 24 | 25 | How to prepare (create and migrate) DB for `development` and `test` environments: 26 | 27 | ``` 28 | % bundle exec hanami db prepare 29 | 30 | % HANAMI_ENV=test bundle exec hanami db prepare 31 | ``` 32 | 33 | Explore Hanami [guides](https://guides.hanamirb.org/), [API docs](http://docs.hanamirb.org/1.3.3/), or jump in [chat](http://chat.hanamirb.org) for help. Enjoy! 🌸 34 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | ruby '3.1.1' 4 | 5 | gem 'rake' 6 | gem 'hanami' 7 | # gem 'hanami-model', git: 'https://github.com/hanami/model.git', require: false 8 | 9 | # gem 'pg' 10 | 11 | gem 'vite_ruby', path: '../../vite_ruby' 12 | 13 | # gem 'vite_hanami', path: '../../vite_hanami' 14 | gem 'vite_hanami' 15 | 16 | group :development do 17 | # Code reloading 18 | # See: https://guides.hanamirb.org/projects/code-reloading 19 | gem 'shotgun', platforms: :ruby 20 | gem 'hanami-webconsole' 21 | end 22 | 23 | group :test, :development do 24 | gem 'dotenv' 25 | gem 'pry-byebug' 26 | end 27 | 28 | group :test do 29 | gem 'rspec' 30 | gem 'capybara' 31 | end 32 | 33 | group :production do 34 | gem 'puma' 35 | end 36 | -------------------------------------------------------------------------------- /examples/rails/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | # Be sure to restart your server when you modify this file. 3 | 4 | # Add new inflection rules using the following format. Inflections 5 | # are locale specific, and you may define rules for as many different 6 | # locales as you wish. All of these examples are active by default: 7 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 8 | # inflect.plural /^(ox)$/i, '\1en' 9 | # inflect.singular /^(ox)en/i, '\1' 10 | # inflect.irregular 'person', 'people' 11 | # inflect.uncountable %w( fish sheep ) 12 | # end 13 | 14 | # These inflection rules are supported but not enabled by default: 15 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 16 | # inflect.acronym 'RESTful' 17 | # end 18 | -------------------------------------------------------------------------------- /.github/workflows/js.yml: -------------------------------------------------------------------------------- 1 | name: JS Build & Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: Vite Plugin Ruby 8 | 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest] 12 | node: [20] 13 | 14 | runs-on: ${{ matrix.os }} 15 | 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - uses: pnpm/action-setup@v4 20 | with: 21 | version: 8.6.5 22 | 23 | - uses: actions/setup-node@v4 24 | with: 25 | cache: 'pnpm' 26 | node-version: ${{ matrix.node }} 27 | 28 | - run: pnpm -C vite-plugin-ruby install --frozen-lockfile 29 | 30 | - name: Build 31 | run: pnpm -C vite-plugin-ruby build 32 | 33 | - name: Test 34 | run: pnpm -C vite-plugin-ruby test 35 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2024-11-05 13:37:33 UTC using RuboCop version 1.66.1. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 1 10 | # Configuration parameters: AllowComments, AllowEmptyLambdas. 11 | Lint/EmptyBlock: 12 | Exclude: 13 | - 'test/mounted_app/test/dummy/config/initializers/content_security_policy.rb' 14 | 15 | # Offense count: 1 16 | # Configuration parameters: AllowComments. 17 | Lint/EmptyClass: 18 | Exclude: 19 | - 'test/test_app/config/application.rb' 20 | -------------------------------------------------------------------------------- /examples/rails/app/frontend/entrypoints/application.ts: -------------------------------------------------------------------------------- 1 | // Example: Load Rails libraries in Vite. 2 | import * as Turbo from '@hotwired/turbo' 3 | import * as ActiveStorage from '@rails/activestorage' 4 | 5 | // Enable Windi CSS styles and preflight 6 | import 'windi.css' 7 | 8 | // Example: Import a stylesheet in app/frontend/styles 9 | import '~/styles/theme.css' 10 | 11 | import '~/entrypoints/example_import' 12 | setTimeout(() => import('~/outer_import'), 5000) 13 | 14 | // Example: Import from an aliased path. 15 | import '@administrator/timer' 16 | 17 | // Import all channels. 18 | import.meta.glob('../channels/**/*_channel.js', { eager: true }) 19 | 20 | Turbo.start() 21 | ActiveStorage.start() 22 | 23 | console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails') 24 | -------------------------------------------------------------------------------- /vite_ruby/default.vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "additionalEntrypoints": ["~/{assets,fonts,icons,images}/**/*"], 3 | "assetHost": null, 4 | "assetsDir": "assets", 5 | "autoBuild": false, 6 | "buildCacheDir": "tmp/cache/vite", 7 | "publicOutputDir": "vite", 8 | "configPath": "config/vite.json", 9 | "devServerConnectTimeout": 0.01, 10 | "packageManager": null, 11 | "publicDir": "public", 12 | "entrypointsDir": "entrypoints", 13 | "sourceCodeDir": "app/frontend", 14 | "skipCompatibilityCheck": false, 15 | "skipProxy": false, 16 | "host": "localhost", 17 | "https": null, 18 | "port": 3036, 19 | "hideBuildConsoleOutput": false, 20 | "viteBinPath": null, 21 | "watchAdditionalPaths": [], 22 | "base": "", 23 | "ssrBuildEnabled": false, 24 | "ssrEntrypoint": "~/ssr/ssr.{js,ts,jsx,tsx}", 25 | "ssrOutputDir": "public/vite-ssr" 26 | } 27 | -------------------------------------------------------------------------------- /vite-plugin-rails/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.5.0 (2023-11-16) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * ssr incompatibility with vite 4 ([#345](https://github.com/ElMassimo/vite_ruby/issues/345)) ([3491bde](https://github.com/ElMassimo/vite_ruby/commit/3491bdedad2b0fcb8a1895efa4dafb3874d14efd)), closes [#333](https://github.com/ElMassimo/vite_ruby/issues/333) 7 | 8 | 9 | ### Features 10 | 11 | * create vite-plugin-rails, an opinionated version of `vite-plugin-ruby` ([#282](https://github.com/ElMassimo/vite_ruby/issues/282)) ([16375fb](https://github.com/ElMassimo/vite_ruby/commit/16375fb1f6f2bf86dff935ca3aaf91c333a796ff)) 12 | * upgrade vite-plugin-rails dependencies to support vite 5 ([b4eade9](https://github.com/ElMassimo/vite_ruby/commit/b4eade9b92413172501df8f762a9c0164633ee95)) 13 | 14 | 15 | 16 | ## vite-plugin-rails 0.1.0 (2022-10-19) 17 | 18 | - Initial Release 19 | -------------------------------------------------------------------------------- /vite-plugin-ruby/default.vite.json: -------------------------------------------------------------------------------- 1 | { 2 | "additionalEntrypoints": ["~/{assets,fonts,icons,images}/**/*"], 3 | "assetHost": null, 4 | "assetsDir": "assets", 5 | "autoBuild": false, 6 | "buildCacheDir": "tmp/cache/vite", 7 | "publicOutputDir": "vite", 8 | "configPath": "config/vite.json", 9 | "devServerConnectTimeout": 0.01, 10 | "packageManager": null, 11 | "publicDir": "public", 12 | "entrypointsDir": "entrypoints", 13 | "sourceCodeDir": "app/frontend", 14 | "skipCompatibilityCheck": false, 15 | "skipProxy": false, 16 | "host": "localhost", 17 | "https": null, 18 | "port": 3036, 19 | "hideBuildConsoleOutput": false, 20 | "viteBinPath": null, 21 | "watchAdditionalPaths": [], 22 | "base": "", 23 | "ssrBuildEnabled": false, 24 | "ssrEntrypoint": "~/ssr/ssr.{js,ts,jsx,tsx}", 25 | "ssrOutputDir": "public/vite-ssr" 26 | } 27 | -------------------------------------------------------------------------------- /examples/rails/example_engine/app/assets/stylesheets/administrator/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/config/boot.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Defines our constants 4 | RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV) 5 | PADRINO_ROOT = File.expand_path('..', __dir__) unless defined?(PADRINO_ROOT) 6 | 7 | # Load our dependencies 8 | require 'bundler/setup' 9 | Bundler.require(:default, RACK_ENV) 10 | 11 | ## 12 | # Require initializers before all other dependencies. 13 | # Dependencies from 'config' folder are NOT re-required on reload. 14 | # 15 | Padrino.dependency_paths.unshift Padrino.root('config/initializers/*.rb') 16 | 17 | ## 18 | # Add your before (RE)load hooks here 19 | # These hooks are run before any dependencies are required. 20 | # 21 | Padrino.before_load do 22 | end 23 | 24 | ## 25 | # Add your after (RE)load hooks here 26 | # 27 | Padrino.after_load do 28 | end 29 | 30 | Padrino.load! 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | pkg 3 | log 4 | tmp 5 | node_modules 6 | .byebug_history 7 | yarn-debug.log* 8 | yarn-error.log* 9 | .yarn-integrity 10 | gemfiles/*.lock 11 | .DS_Store 12 | 13 | # Vite on Rails 14 | /public/vite 15 | /public/vite-dev 16 | /public/vite-test 17 | test/test_app/public/vite-production 18 | node_modules 19 | *.local 20 | .DS_Store 21 | 22 | # Vitepress 23 | dist 24 | examples_dist 25 | node_modules 26 | coverage 27 | .nyc_output 28 | .rpt2_cache 29 | .env 30 | local.log 31 | .DS_Store 32 | e2e/reports 33 | e2e/screenshots 34 | __build__ 35 | playground_dist 36 | yarn-error.log 37 | *.log 38 | temp 39 | markdown 40 | explorations 41 | selenium-server.log 42 | 43 | # Algolia 44 | .algolia.env 45 | 46 | # Hanami 47 | .env.local 48 | .env.*.local 49 | 50 | .pnpm-debug.log 51 | test/mounted_app/test/dummy/bin/vite 52 | test/mounted_app/test/dummy/bin/racc 53 | 54 | examples/with_engine 55 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/apps/web/frontend/entrypoints/styles.scss: -------------------------------------------------------------------------------- 1 | *, ::after, ::before { 2 | box-sizing: border-box; 3 | } 4 | 5 | html { 6 | font-family: ui-sans-serif, system-ui, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 7 | line-height: 1.5; 8 | } 9 | 10 | body { 11 | font-family: inherit; 12 | line-height: inherit; 13 | margin: 0; 14 | } 15 | 16 | header { 17 | display: grid; 18 | height: 100vh; 19 | margin: 0 auto; 20 | padding-bottom: 20vh; 21 | place-content: center; 22 | } 23 | 24 | .logo { 25 | height: 0; 26 | opacity: 0; 27 | } 28 | 29 | .hero { 30 | box-sizing: border-box; 31 | font-size: clamp(4rem, 10vw, 4.5rem); 32 | line-height: 1; 33 | font-weight: 800; 34 | height: 128px; 35 | margin: 0; 36 | text-align: center; 37 | } 38 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("bundle", __dir__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rake", "rake") 30 | -------------------------------------------------------------------------------- /test/test_app/public/vite-production/.vite/manifest-assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "entrypoints/sassy.scss": { 3 | "file": "assets/sassy.3560956f.css", 4 | "src": "entrypoints/sassy.scss" 5 | }, 6 | "../assets/theme.css": { 7 | "file": "assets/theme.e6d9734b.css", 8 | "src": "app/assets/theme.css" 9 | }, 10 | "entrypoints/app.css": { 11 | "file": "assets/app.517bf154.css", 12 | "src": "entrypoints/app.css" 13 | }, 14 | "images/logo.png": { 15 | "file": "assets/logo.f42fb7ea.png", 16 | "src": "images/logo.png" 17 | }, 18 | "images/logo-2x.png": { 19 | "file": "assets/logo-2x.bs8d7a77.png", 20 | "src": "images/logo-2x.png" 21 | }, 22 | "images/logo.svg": { 23 | "file": "assets/logo.322aae0c.svg", 24 | "src": "images/logo.svg" 25 | }, 26 | "../assets/logo.png": { 27 | "file": "assets/logo.03d6d6da.png", 28 | "src": "app/assets/logo.png" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bin/rubocop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rubocop' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("bundle", __dir__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rubocop", "rubocop") 30 | -------------------------------------------------------------------------------- /examples/rails/bin/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'vite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("vite_ruby", "vite") 30 | -------------------------------------------------------------------------------- /test/test_app/bin/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'vite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("bundle", __dir__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("vite_ruby", "vite") 30 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rake", "rake") 30 | -------------------------------------------------------------------------------- /examples/rails/bin/rspec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rspec' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rspec-core", "rspec") 30 | -------------------------------------------------------------------------------- /examples/hanami_bookshelf/bin/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'vite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("vite_ruby", "vite") 30 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rake", "rake") 30 | -------------------------------------------------------------------------------- /examples/rails/example_engine/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rake", "rake") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/m: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'm' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("m", "m") 30 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/bin/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'vite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("vite_ruby", "vite") 30 | -------------------------------------------------------------------------------- /examples/rails/example_engine/bin/vite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'vite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("vite_ruby", "vite") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/pry: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'pry' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("pry", "pry") 30 | -------------------------------------------------------------------------------- /examples/rails/test_helpers/home_test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class HomeTestHelper < BaseTestHelper 4 | HERO_PATH = 'app/frontend/components/Hero.jsx' 5 | 6 | # Aliases: Semantic aliases for locators, can be used in most DSL methods. 7 | aliases( 8 | el: 'header', 9 | ) 10 | 11 | # Finders: A convenient way to get related data or nested elements. 12 | 13 | # Actions: Encapsulate complex actions to provide a cleaner interface. 14 | # Public: Allows to test HMR in the test environment. 15 | def rewrite(text, to:) 16 | new_content = File.read(HERO_PATH).sub(text, to) 17 | File.open(HERO_PATH, 'w') { |file| file.write(new_content) } 18 | end 19 | 20 | def revert_changes 21 | `git checkout #{ HERO_PATH }` 22 | end 23 | 24 | # Assertions: Check on element properties, used with `should` and `should_not`. 25 | 26 | # Background: Helpers to add/modify/delete data in the database or session. 27 | end 28 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rake' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rake", "rake") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/thor: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'thor' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("thor", "thor") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/rackup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rackup' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rack", "rackup") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rails' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("railties", "rails") 30 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/bin/padrino: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'padrino' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("padrino-core", "padrino") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/byebug: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'byebug' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("byebug", "byebug") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/coderay: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'coderay' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("coderay", "coderay") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/rubocop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rubocop' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rubocop", "rubocop") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'spring' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("spring", "spring") 30 | -------------------------------------------------------------------------------- /vite-plugin-ruby/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-ruby-example", 3 | "version": "0.0.0", 4 | "private": true, 5 | "license": "MIT", 6 | "scripts": { 7 | "dev": "cross-env DEBUG=vite-plugin-ruby:* vite --open", 8 | "build": "cross-env DEBUG=vite-plugin-ruby:* vite build --mode production", 9 | "preview": "cross-env RAILS_ENV=production DEBUG=vite-plugin-ruby:* vite preview --open" 10 | }, 11 | "devDependencies": { 12 | "@inertiajs/inertia": "^0.11.1", 13 | "@inertiajs/inertia-vue3": "^0.6.0", 14 | "@inertiajs/server": "^0.1.0", 15 | "@vitejs/plugin-legacy": "^5.0.0", 16 | "@vitejs/plugin-vue": "^4.5.0", 17 | "@vue/server-renderer": "^3.3.8", 18 | "@types/node": "^18", 19 | "cross-env": "^7.0.3", 20 | "sass": "^1.59.3", 21 | "terser": "^5.16.6", 22 | "typescript": "^4.9.5", 23 | "vite": "^5.0.0", 24 | "vite-plugin-ruby": "workspace:*", 25 | "vue": "^3.3.8" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /vite_hanami/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # [3.0.0](https://github.com/ElMassimo/vite_ruby/compare/vite_hanami@0.5.3...vite_hanami@3.0.0) (2021-08-16) 2 | 3 | See https://github.com/ElMassimo/vite_ruby/pull/116 for features and breaking changes. 4 | 5 | ## [0.5.3](https://github.com/ElMassimo/vite_ruby/compare/vite_hanami@0.5.2...vite_hanami@0.5.3) (2021-04-21) 6 | 7 | 8 | ### Features 9 | 10 | * Add helpers to enable HMR when using @vitejs/plugin-react-refresh ([a80f286](https://github.com/ElMassimo/vite_ruby/commit/a80f286d4305bbae29ea7cea42a4329a530f43fa)) 11 | 12 | 13 | 14 | ## [0.5.2](https://github.com/ElMassimo/vite_ruby/compare/vite_hanami@0.5.1...vite_hanami@0.5.2) (2021-03-07) 15 | 16 | - Add a bounded requirement to `vite_ruby` dependency. 17 | 18 | ## Vite Hanami 0.5.1 (2020-02-10) 19 | 20 | - Install rake tasks in Rakefile by default. 21 | 22 | ## Vite Hanami 0.5.0 (2020-02-09) 23 | 24 | - Initial release, includes installation samples and tag helpers. 25 | -------------------------------------------------------------------------------- /examples/rails/example_engine/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails gems 3 | # installed from the root of your application. 4 | 5 | ENGINE_ROOT = File.expand_path('..', __dir__) 6 | ENGINE_PATH = File.expand_path('../lib/administrator/engine', __dir__) 7 | 8 | # Set up gems listed in the Gemfile. 9 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 10 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 11 | 12 | require "rails" 13 | # Pick the frameworks you want: 14 | require "active_model/railtie" 15 | require "active_job/railtie" 16 | # require "active_record/railtie" 17 | # require "active_storage/engine" 18 | require "action_controller/railtie" 19 | # require "action_mailer/railtie" 20 | require "action_view/railtie" 21 | # require "action_cable/engine" 22 | # require "sprockets/railtie" 23 | # require "rails/test_unit/railtie" 24 | require "rails/engine/commands" 25 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/nokogiri: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'nokogiri' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("nokogiri", "nokogiri") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/ruby-parse: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'ruby-parse' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("parser", "ruby-parse") 30 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/sprockets: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'sprockets' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("sprockets", "sprockets") 30 | -------------------------------------------------------------------------------- /examples/rails/README.md: -------------------------------------------------------------------------------- 1 |

2 | Vite ⚡️ Rails 3 |

4 | 5 | [vite_rails]: https://github.com/ElMassimo/vite_ruby 6 | [heroku]: https://vite-rails-demo.herokuapp.com/ 7 | [live demo]: https://vite-rails-demo.herokuapp.com/ 8 | 9 | This app is an example using [vite_rails] to manage assets with Vite. 10 | 11 | A [live demo] is running on [Heroku]. 12 | 13 | ## Installation 💿 14 | 15 | If using Docker, run `bin/docker_setup` to build the images and create the db. 16 | 17 | Alternatively, you can run: 18 | 19 | - bundle install: Install the ruby gems 20 | - yarn install: Install the npm packages 21 | - bin/rake db:create db:migrate: Create the database and tables 22 | 23 | ## Development 🚀 24 | 25 | If using Docker, run `bin/docker` to start the services. 26 | 27 | Alternatively, you can run: 28 | 29 | - bin/rails s: Starts the Rails dev server 30 | - bin/vite dev: Starts the Vite.js dev server 31 | -------------------------------------------------------------------------------- /test/dev_server_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | class DevServerTest < ViteRuby::Test 6 | def test_not_running 7 | refute_predicate ViteRuby.instance, :dev_server_running? 8 | 9 | refresh_config(mode: "development") 10 | 11 | refute_predicate ViteRuby.instance, :dev_server_running? 12 | 13 | running_checked_at = ViteRuby.instance.instance_variable_get(:@running_checked_at) 14 | 15 | assert_in_delta(Time.now.to_f, running_checked_at.to_f, 0.01) 16 | end 17 | 18 | def test_running 19 | refresh_config(mode: "development") 20 | ViteRuby.instance.instance_variable_set(:@running, true) 21 | ViteRuby.instance.instance_variable_set(:@running_checked_at, Time.now) 22 | 23 | assert_predicate ViteRuby.instance, :dev_server_running? 24 | ensure 25 | ViteRuby.instance.remove_instance_variable(:@running) 26 | ViteRuby.instance.remove_instance_variable(:@running_checked_at) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /test/mounted_app/test/dummy/bin/ruby-rewrite: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'ruby-rewrite' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("parser", "ruby-rewrite") 30 | -------------------------------------------------------------------------------- /examples/rails/db/schema.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # This file is auto-generated from the current state of the database. Instead 4 | # of editing this file, please use the migrations feature of Active Record to 5 | # incrementally modify your database, and then regenerate this schema definition. 6 | # 7 | # This file is the source Rails uses to define your schema when running `bin/rails 8 | # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 9 | # be faster and is potentially less error prone than running all of your 10 | # migrations from scratch. Old migrations may fail to apply correctly if those 11 | # migrations use external dependencies or application code. 12 | # 13 | # It's strongly recommended that you check this file into your version control system. 14 | 15 | ActiveRecord::Schema.define(version: 0) do 16 | # These are extensions that must be enabled in order to support this database 17 | enable_extension 'plpgsql' 18 | end 19 | -------------------------------------------------------------------------------- /examples/padrino_blog_tutorial/app/frontend/entrypoints/styles.css: -------------------------------------------------------------------------------- 1 | *, ::after, ::before { 2 | box-sizing: border-box; 3 | } 4 | 5 | html { 6 | font-family: ui-sans-serif, system-ui, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; 7 | line-height: 1.5; 8 | } 9 | 10 | body { 11 | font-family: inherit; 12 | line-height: inherit; 13 | margin: 0; 14 | } 15 | 16 | header { 17 | display: grid; 18 | height: 100vh; 19 | margin: 0 auto; 20 | padding-top: 20vh; 21 | place-content: center; 22 | } 23 | 24 | .logo { 25 | height: 0; 26 | opacity: 0; 27 | } 28 | 29 | .banner { 30 | align-items: center; 31 | display: grid; 32 | grid-template-columns: 1fr 1fr; 33 | box-sizing: border-box; 34 | font-size: clamp(4rem, 10vw, 4.5rem); 35 | line-height: 1; 36 | font-weight: 800; 37 | height: 128px; 38 | margin: 0; 39 | text-align: center; 40 | } 41 | -------------------------------------------------------------------------------- /examples/rails/example_engine/lib/administrator/engine.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Administrator 4 | class Engine < ::Rails::Engine 5 | isolate_namespace Administrator 6 | delegate :vite_ruby, to: :class 7 | 8 | def self.vite_ruby 9 | @vite_ruby ||= ViteRuby.new(root: root) 10 | end 11 | 12 | # Expose compiled assets via Rack::Static when running in the host app. 13 | config.app_middleware.use(Rack::Static, 14 | urls: ["/#{ vite_ruby.config.public_output_dir }"], 15 | root: root.join(vite_ruby.config.public_dir)) 16 | 17 | initializer 'vite_rails_engine.proxy' do |app| 18 | if vite_ruby.run_proxy? 19 | app.middleware.insert_before 0, ViteRuby::DevServerProxy, ssl_verify_none: true, vite_ruby: vite_ruby 20 | end 21 | end 22 | 23 | initializer 'vite_rails_engine.logger' do 24 | config.after_initialize do 25 | vite_ruby.logger = Rails.logger 26 | end 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /test/test_app/config/application.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "action_controller/railtie" 4 | require "action_view/railtie" 5 | 6 | class Rails::Console; end 7 | 8 | if RUBY_VERSION.start_with?("2.4") 9 | require "vite_rails_legacy" 10 | ViteRails = ViteRailsLegacy 11 | else 12 | require "spring/configuration" 13 | Spring.application_root = File.expand_path("..", __dir__) 14 | require "vite_rails" 15 | end 16 | 17 | require "vite_plugin_legacy" 18 | 19 | module TestApp 20 | class Application < ::Rails::Application 21 | config.load_defaults Rails::VERSION::STRING.to_f 22 | config.secret_key_base = SecureRandom.hex 23 | config.eager_load = true 24 | config.active_support.test_order = :sorted 25 | 26 | if Rails.gem_version >= Gem::Version.new("7.0.0") 27 | # Option added in Rails 7.0, defaults to false. Some helper_test tests assume true. 28 | config.action_view.apply_stylesheet_media_default = true 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/runner_test.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | class RunnerTest < ViteRuby::Test 6 | def test_dev_server_command 7 | assert_run_command(flags: ["--mode", "production"]) 8 | end 9 | 10 | def test_dev_server_command_with_argument 11 | assert_run_command("--quiet", flags: ["--mode", "production"]) 12 | end 13 | 14 | def test_build_command 15 | assert_run_command("build", flags: ["--mode", "production"]) 16 | end 17 | 18 | def test_build_command_with_argument 19 | with_rails_env("development") do 20 | assert_run_command("build", "--emptyOutDir", flags: ["--mode", "development"]) 21 | end 22 | end 23 | 24 | def test_command_capture 25 | ViteRuby::Runner.stub_any_instance(:vite_executable, "echo") { 26 | stdout, stderr, status = ViteRuby.run(['"Hello"']) 27 | 28 | assert_equal %("Hello" --mode production\n), stdout 29 | assert_equal "", stderr 30 | assert status 31 | } 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /bin/m: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'm' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("bundle", __dir__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | ARGV.each_with_index do |arg, index| 30 | ARGV[index] = arg.sub(File.expand_path(Dir.pwd), "") 31 | end 32 | 33 | load Gem.bin_path("m", "m") 34 | -------------------------------------------------------------------------------- /examples/rails/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/cli/ssr.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class ViteRuby::CLI::SSR < ViteRuby::CLI::Vite 4 | DEFAULT_ENV = CURRENT_ENV || "production" 5 | JS_EXTENSIONS = %w[js mjs cjs] 6 | 7 | desc "Run the resulting app from building in SSR mode." 8 | executable_options 9 | 10 | def call(mode:, inspect: false, trace_deprecation: false) 11 | ViteRuby.env["VITE_RUBY_MODE"] = mode 12 | 13 | ssr_entrypoint = JS_EXTENSIONS 14 | .map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ext}") } 15 | .find(&:exist?) 16 | 17 | raise ArgumentError, "No ssr entrypoint found `#{ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root)}/ssr.{#{JS_EXTENSIONS.join(",")}}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint 18 | 19 | cmd = [ 20 | "node", 21 | ("--inspect-brk" if inspect), 22 | ("--trace-deprecation" if trace_deprecation), 23 | ssr_entrypoint, 24 | ] 25 | Kernel.exec(*cmd.compact.map(&:to_s)) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /vite-plugin-ruby/src/constants.ts: -------------------------------------------------------------------------------- 1 | // Internal: Inferred mode, since Vite doesn't yet expose it to its plugins. 2 | export const APP_ENV = process.env.RAILS_ENV || process.env.RACK_ENV || process.env.APP_ENV 3 | 4 | // Internal: Prefix used for environment variables that modify the configuration. 5 | export const ENV_PREFIX = 'VITE_RUBY' 6 | 7 | // Internal: Key of the vite.json file that is applied to all environments. 8 | export const ALL_ENVS_KEY = 'all' 9 | 10 | // Internal: Extensions of CSS files or known precompilers. 11 | export const KNOWN_CSS_EXTENSIONS = [ 12 | 'css', 13 | 'less', 14 | 'sass', 15 | 'scss', 16 | 'styl', 17 | 'stylus', 18 | 'pcss', 19 | 'postcss', 20 | ] 21 | 22 | // Internal: Types of files that Vite should process correctly as entrypoints. 23 | export const KNOWN_ENTRYPOINT_TYPES = [ 24 | 'html', 25 | 'jsx?', 26 | 'tsx?', 27 | ...KNOWN_CSS_EXTENSIONS, 28 | ] 29 | 30 | export const ENTRYPOINT_TYPES_REGEX = new RegExp( 31 | `\\.(${KNOWN_ENTRYPOINT_TYPES.join('|')})(\\?.*)?$`, 32 | ) 33 | -------------------------------------------------------------------------------- /vite-plugin-rails/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite-plugin-rails-example", 3 | "version": "0.0.0", 4 | "private": true, 5 | "license": "MIT", 6 | "type": "module", 7 | "scripts": { 8 | "dev": "cross-env DEBUG=vite-plugin-ruby:* vite --open", 9 | "build": "cross-env DEBUG=vite-plugin-ruby:* vite build --mode production --emptyOutDir", 10 | "preview": "cross-env RAILS_ENV=production DEBUG=vite-plugin-ruby:* vite preview --open" 11 | }, 12 | "devDependencies": { 13 | "@inertiajs/inertia": "^0.11.1", 14 | "@inertiajs/inertia-vue3": "^0.6.0", 15 | "@inertiajs/server": "^0.1.0", 16 | "@vitejs/plugin-legacy": "^5.0.0", 17 | "@vitejs/plugin-vue": "^4.5.0", 18 | "@vue/server-renderer": "^3.3.8", 19 | "@types/node": "^18", 20 | "cross-env": "^7.0.3", 21 | "sass": "^1.59.3", 22 | "terser": "^5.16.6", 23 | "typescript": "^4.9.5", 24 | "vite": "^5.0.0", 25 | "vite-plugin-rails": "workspace:*", 26 | "vite-plugin-ruby": "workspace:*", 27 | "vue": "^3.3.8" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /vite_rails/templates/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | // To see this message, add the following to the `` section in your 2 | // views/layouts/application.html.erb 3 | // 4 | // <%= vite_client_tag %> 5 | // <%= vite_javascript_tag 'application' %> 6 | console.log('Vite ⚡️ Rails') 7 | 8 | // If using a TypeScript entrypoint file: 9 | // <%= vite_typescript_tag 'application' %> 10 | // 11 | // If you want to use .jsx or .tsx, add the extension: 12 | // <%= vite_javascript_tag 'application.jsx' %> 13 | 14 | console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails') 15 | 16 | // Example: Load Rails libraries in Vite. 17 | // 18 | // import * as Turbo from '@hotwired/turbo' 19 | // Turbo.start() 20 | // 21 | // import ActiveStorage from '@rails/activestorage' 22 | // ActiveStorage.start() 23 | // 24 | // // Import all channels. 25 | // const channels = import.meta.glob('./**/*_channel.js', { eager: true }) 26 | 27 | // Example: Import a stylesheet in app/frontend/index.css 28 | // import '~/index.css' 29 | -------------------------------------------------------------------------------- /vite_rails_legacy/templates/entrypoints/application.js: -------------------------------------------------------------------------------- 1 | // To see this message, add the following to the `` section in your 2 | // views/layouts/application.html.erb 3 | // 4 | // <%= vite_client_tag %> 5 | // <%= vite_javascript_tag 'application' %> 6 | console.log('Vite ⚡️ Rails') 7 | 8 | // If using a TypeScript entrypoint file: 9 | // <%= vite_typescript_tag 'application' %> 10 | // 11 | // If you want to use .jsx or .tsx, add the extension: 12 | // <%= vite_javascript_tag 'application.jsx' %> 13 | 14 | console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails') 15 | 16 | // Example: Load Rails libraries in Vite. 17 | // 18 | // import * as Turbo from '@hotwired/turbo' 19 | // Turbo.start() 20 | // 21 | // import ActiveStorage from '@rails/activestorage' 22 | // ActiveStorage.start() 23 | // 24 | // // Import all channels. 25 | // const channels = import.meta.glob('./**/*_channel.js', { eager: true }) 26 | 27 | // Example: Import a stylesheet in app/frontend/index.css 28 | // import '~/index.css' 29 | -------------------------------------------------------------------------------- /examples/rails/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog", 3 | "private": true, 4 | "license": "MIT", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite" 8 | }, 9 | "engines": { 10 | "node": "18", 11 | "pnpm": "8" 12 | }, 13 | "dependencies": { 14 | "@bugsnag/js": "^7.20.2", 15 | "@bugsnag/plugin-react": "^7.19.0", 16 | "@hotwired/turbo": "^7.3.0", 17 | "@rails/actioncable": "^7.0.4", 18 | "@rails/activestorage": "^7.0.4", 19 | "react": "^18.2.0", 20 | "react-dom": "^18.2.0" 21 | }, 22 | "version": "0.1.0", 23 | "devDependencies": { 24 | "@types/rails__activestorage": "^7.0.1", 25 | "@vitejs/plugin-legacy": "4.0.3", 26 | "@vitejs/plugin-react": "^4.0.0", 27 | "less": "^4.1.3", 28 | "ms": "^2.1.3", 29 | "sass": "^1.62.1", 30 | "stylus": "^0.54.8", 31 | "terser": "^5.17.1", 32 | "vite": "^4.3.0", 33 | "vite-plugin-bugsnag": "^2.0.2", 34 | "vite-plugin-rails": "^0.1.0", 35 | "vite-plugin-ruby": "^3.2.0", 36 | "vite-plugin-windicss": "^1.8.10" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vite_hanami/vite_hanami.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.push File.expand_path("./lib", __dir__) 4 | require "vite_hanami/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "vite_hanami" 8 | s.version = ViteHanami::VERSION 9 | s.authors = ["Máximo Mussini"] 10 | s.email = ["maximomussini@gmail.com"] 11 | s.summary = "Use Vite in Hanami and bring joy to your JavaScript experience" 12 | s.homepage = "https://github.com/ElMassimo/vite_ruby" 13 | s.license = "MIT" 14 | 15 | s.metadata = { 16 | "source_code_uri" => "https://github.com/ElMassimo/vite_ruby/tree/vite_hanami@#{ViteHanami::VERSION}/vite_hanami", 17 | "changelog_uri" => "https://github.com/ElMassimo/vite_ruby/blob/vite_hanami@#{ViteHanami::VERSION}/vite_hanami/CHANGELOG.md", 18 | "rubygems_mfa_required" => "true", 19 | } 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 2.5") 22 | 23 | s.add_dependency "vite_ruby", "~> 3.0" 24 | 25 | s.files = Dir.glob("{lib,templates}/**/*") + %w[README.md CHANGELOG.md LICENSE.txt] 26 | end 27 | -------------------------------------------------------------------------------- /vite_padrino/vite_padrino.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.push File.expand_path("./lib", __dir__) 4 | require "vite_padrino/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "vite_padrino" 8 | s.version = VitePadrino::VERSION 9 | s.authors = ["Máximo Mussini"] 10 | s.email = ["maximomussini@gmail.com"] 11 | s.summary = "Use Vite in Padrino and bring joy to your JavaScript experience" 12 | s.homepage = "https://github.com/ElMassimo/vite_ruby" 13 | s.license = "MIT" 14 | 15 | s.metadata = { 16 | "source_code_uri" => "https://github.com/ElMassimo/vite_ruby/tree/vite_padrino@#{VitePadrino::VERSION}/vite_padrino", 17 | "changelog_uri" => "https://github.com/ElMassimo/vite_ruby/blob/vite_padrino@#{VitePadrino::VERSION}/vite_padrino/CHANGELOG.md", 18 | "rubygems_mfa_required" => "true", 19 | } 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 2.5") 22 | 23 | s.add_dependency "vite_ruby", "~> 3.0" 24 | 25 | s.files = Dir.glob("{lib,templates}/**/*") + %w[README.md CHANGELOG.md LICENSE.txt] 26 | end 27 | -------------------------------------------------------------------------------- /examples/rails/spec/support/capybara.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'capybara/cuprite' 4 | 5 | Capybara.register_driver(:cuprite) do |app, _options| 6 | cuprite_timeout = ENV.fetch('CUPRITE_TIMEOUT', 30).to_i 7 | 8 | Capybara::Cuprite::Driver.new( 9 | app, 10 | js_errors: true, 11 | browser_options: { 12 | 'disable-infobars' => nil, 13 | 'no-sandbox' => nil, 14 | 'disable-dev-shm-usage' => nil, 15 | 'disable-site-isolation-trials' => nil, 16 | }, 17 | timeout: cuprite_timeout, 18 | process_timeout: cuprite_timeout, 19 | inspector: !ENV['CI'], 20 | headless: %w[true 1 yes].include?(ENV['HEADLESS'] || ENV['CI']), 21 | slowmo: ENV['SLOWMO'] == 'true' ? 0.1 : ENV['SLOWMO'], 22 | ) 23 | end 24 | 25 | Capybara.configure do |config| 26 | config.default_driver = :cuprite 27 | config.javascript_driver = :cuprite 28 | 29 | config.match = :smart 30 | config.exact = true 31 | config.ignore_hidden_elements = true 32 | config.default_max_wait_time = 3 33 | config.default_normalize_ws = true 34 | end 35 | -------------------------------------------------------------------------------- /scripts/verifyCommit.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | /* eslint-disable import/order */ 3 | const args = require('minimist')(process.argv.slice(2)) 4 | const msgPath = args._[0] 5 | const msg = require('fs').readFileSync(msgPath, 'utf-8').trim() 6 | 7 | const releaseRE = /^v\d/ 8 | const commitRE = /^(revert: )?(feat|fix|docs|dx|refactor|perf|test|workflow|build|ci|chore|types|wip|release|deps)(\(.+\))?: .{1,50}/ 9 | 10 | if (!releaseRE.test(msg) && !commitRE.test(msg)) { 11 | console.log() 12 | const chalk = require('chalk') 13 | console.error( 14 | ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red( 15 | 'invalid commit message format.', 16 | )}\n\n${ 17 | chalk.red( 18 | ' Proper commit message format is required for automated changelog generation. Examples:\n\n', 19 | ) 20 | } ${chalk.green('feat: add \'comments\' option')}\n` 21 | + ` ${chalk.green('fix: handle events on blur (close #28)')}\n\n${ 22 | chalk.red(' See .github/commit-convention.md for more details.\n')}`, 23 | ) 24 | process.exit(1) 25 | } 26 | -------------------------------------------------------------------------------- /examples/rails/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | /db/*.sqlite3-* 14 | 15 | # Ignore all logfiles and tempfiles. 16 | /log/* 17 | /tmp/* 18 | !/log/.keep 19 | !/tmp/.keep 20 | 21 | # Ignore pidfiles, but keep the directory. 22 | /tmp/pids/* 23 | !/tmp/pids/ 24 | !/tmp/pids/.keep 25 | 26 | # Ignore uploaded files in development. 27 | /storage/* 28 | !/storage/.keep 29 | 30 | /public/assets 31 | .byebug_history 32 | 33 | # Ignore master key for decrypting credentials and more. 34 | /config/master.key 35 | 36 | /public/packs 37 | /public/packs-test 38 | /node_modules 39 | /yarn-error.log 40 | yarn-debug.log* 41 | .yarn-integrity 42 | 43 | # Vite Ruby 44 | /public/vite* 45 | node_modules 46 | *.local 47 | .DS_Store 48 | -------------------------------------------------------------------------------- /examples/rails/example_engine/administrator.gemspec: -------------------------------------------------------------------------------- 1 | require_relative "lib/administrator/version" 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = "administrator" 5 | spec.version = Administrator::VERSION 6 | spec.authors = ["Maximo Mussini"] 7 | spec.email = ["maximomussini@gmail.com"] 8 | spec.homepage = "https://github.com/ElMassimo/vite_ruby/tree/main/examples/example_engine" 9 | spec.summary = "Example of how to use Vite Ruby inside a Rails engine" 10 | spec.license = "MIT" 11 | 12 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 13 | # to allow pushing to a single host or delete this section to allow pushing to any host. 14 | spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" 15 | 16 | spec.metadata["homepage_uri"] = spec.homepage 17 | spec.metadata["source_code_uri"] = spec.homepage 18 | 19 | spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] 20 | 21 | spec.add_dependency "rails" 22 | spec.add_dependency "vite_rails" 23 | spec.add_dependency "bootsnap" 24 | end 25 | -------------------------------------------------------------------------------- /vite_plugin_legacy/vite_plugin_legacy.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.push File.expand_path("./lib", __dir__) 4 | require "vite_plugin_legacy/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "vite_plugin_legacy" 8 | s.version = VitePluginLegacy::VERSION 9 | s.authors = ["Máximo Mussini"] 10 | s.email = ["maximomussini@gmail.com"] 11 | s.summary = "Tag helpers for @vitejs/plugin-legacy to support legacy browsers" 12 | s.homepage = "https://github.com/ElMassimo/vite_ruby" 13 | s.license = "MIT" 14 | 15 | s.metadata = { 16 | "source_code_uri" => "https://github.com/ElMassimo/vite_ruby/tree/vite_plugin_legacy@#{VitePluginLegacy::VERSION}/vite_plugin_legacy", 17 | "changelog_uri" => "https://github.com/ElMassimo/vite_ruby/blob/vite_plugin_legacy@#{VitePluginLegacy::VERSION}/vite_plugin_legacy/CHANGELOG.md", 18 | "rubygems_mfa_required" => "true", 19 | } 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 2.4") 22 | 23 | s.add_dependency "vite_ruby", "~> 3.0", ">= 3.0.4" 24 | 25 | s.files = Dir.glob("{lib,templates}/**/*") + %w[README.md CHANGELOG.md LICENSE.txt] 26 | end 27 | -------------------------------------------------------------------------------- /vite_padrino/lib/vite_padrino/installation.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "vite_padrino" 4 | 5 | # Internal: Extends the base installation script from Vite Ruby to work for a 6 | # typical Padrino app. 7 | module VitePadrino::Installation 8 | PADRINO_TEMPLATES = Pathname.new(File.expand_path("../../templates", __dir__)) 9 | 10 | # Override: Setup a typical apps/web Padrino app to use Vite. 11 | def setup_app_files 12 | cp PADRINO_TEMPLATES.join("config/padrino-vite.json"), config.config_path 13 | inject_line_after root.join("app/app.rb"), "register", " register VitePadrino" 14 | append root.join("Rakefile"), <<~RAKE 15 | require 'vite_padrino' 16 | ViteRuby.install_tasks 17 | RAKE 18 | end 19 | 20 | # Override: Inject the vite client and sample script to the default HTML template. 21 | def install_sample_files 22 | super 23 | inject_line_after root.join("app/views/layouts/application.haml"), "%title", <<-HTML 24 | = vite_client_tag 25 | = vite_javascript_tag 'application' 26 | HTML 27 | end 28 | end 29 | 30 | ViteRuby::CLI::Install.prepend(VitePadrino::Installation) 31 | -------------------------------------------------------------------------------- /vite_ruby/lib/vite_ruby/io.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "open3" 4 | 5 | # Public: Builds on top of Ruby I/O open3 providing a friendlier experience. 6 | module ViteRuby::IO 7 | class << self 8 | # Internal: A modified version of capture3 that can continuosly print stdout. 9 | # NOTE: Streaming output provides a better UX when running bin/vite build. 10 | def capture(*cmd, with_output: $stdout.method(:puts), stdin_data: "", **opts) 11 | return Open3.capture3(*cmd, **opts) unless with_output 12 | 13 | Open3.popen3(*cmd, **opts) { |stdin, stdout, stderr, wait_threads| 14 | stdin << stdin_data 15 | stdin.close 16 | out = Thread.new { read_lines(stdout, &with_output) } 17 | err = Thread.new { stderr.read } 18 | [out.value, err.value.to_s, wait_threads.value] 19 | } 20 | end 21 | 22 | # Internal: Reads and yield every line in the stream. Returns the full content. 23 | def read_lines(io) 24 | buffer = +"" 25 | while line = io.gets 26 | buffer << line 27 | yield line 28 | end 29 | buffer 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/rails/example_engine/MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Maximo Mussini 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vite_rails_legacy/lib/vite_rails_legacy/engine.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rails/railtie" 4 | 5 | class ViteRailsLegacy::Engine < Rails::Engine 6 | initializer "vite_rails.proxy" do |app| 7 | app.middleware.insert_before 0, "ViteRuby::DevServerProxy", ssl_verify_none: true if ViteRuby.run_proxy? 8 | end 9 | 10 | initializer "vite_rails_legacy.helper" do 11 | ActiveSupport.on_load(:action_controller) do 12 | ActionController::Base.helper(ViteRailsLegacy::TagHelpers) 13 | end 14 | 15 | ActiveSupport.on_load(:action_view) do 16 | include ViteRailsLegacy::TagHelpers 17 | end 18 | end 19 | 20 | initializer "vite_rails.logger" do 21 | config.after_initialize do 22 | ViteRuby.instance.logger = Rails.logger 23 | end 24 | end 25 | 26 | initializer "vite_rails.bootstrap" do 27 | if defined?(Rails::Server) || defined?(Rails::Console) 28 | ViteRuby.bootstrap 29 | if defined?(Spring) 30 | require "spring/watcher" 31 | Spring.after_fork { ViteRuby.bootstrap } 32 | Spring.watch(ViteRuby.config.config_path) 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /vite_rails_legacy/vite_rails_legacy.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.push File.expand_path("./lib", __dir__) 4 | require "vite_rails_legacy/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "vite_rails_legacy" 8 | s.version = ViteRailsLegacy::VERSION 9 | s.authors = ["Máximo Mussini"] 10 | s.email = ["maximomussini@gmail.com"] 11 | s.summary = "Use Vite in Rails 4 and bring joy to your JavaScript experience" 12 | s.homepage = "https://github.com/ElMassimo/vite_ruby" 13 | s.license = "MIT" 14 | 15 | s.metadata = { 16 | "source_code_uri" => "https://github.com/ElMassimo/vite_ruby/tree/vite_rails_legacy@#{ViteRailsLegacy::VERSION}/vite_rails_legacy", 17 | "changelog_uri" => "https://github.com/ElMassimo/vite_ruby/blob/vite_rails_legacy@#{ViteRailsLegacy::VERSION}/vite_rails_legacy/CHANGELOG.md", 18 | "rubygems_mfa_required" => "true", 19 | } 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 2.4") 22 | 23 | s.add_dependency "railties", "< 5" 24 | s.add_dependency "vite_ruby", "~> 3.0" 25 | 26 | s.files = Dir.glob("{lib,templates}/**/*") + %w[README.md CHANGELOG.md LICENSE.txt] 27 | end 28 | -------------------------------------------------------------------------------- /vite_rails/vite_rails.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | $LOAD_PATH.push File.expand_path("./lib", __dir__) 4 | require "vite_rails/version" 5 | 6 | Gem::Specification.new do |s| 7 | s.name = "vite_rails" 8 | s.version = ViteRails::VERSION 9 | s.authors = ["Máximo Mussini"] 10 | s.email = ["maximomussini@gmail.com"] 11 | s.summary = "Use Vite in Rails and bring joy to your JavaScript experience" 12 | s.homepage = "https://github.com/ElMassimo/vite_ruby" 13 | s.license = "MIT" 14 | 15 | s.metadata = { 16 | "source_code_uri" => "https://github.com/ElMassimo/vite_ruby/tree/vite_rails@#{ViteRails::VERSION}/vite_rails", 17 | "changelog_uri" => "https://github.com/ElMassimo/vite_ruby/blob/vite_rails@#{ViteRails::VERSION}/vite_rails/CHANGELOG.md", 18 | "rubygems_mfa_required" => "true", 19 | } 20 | 21 | s.required_ruby_version = Gem::Requirement.new(">= 2.5") 22 | 23 | s.add_dependency "railties", ">= 5.1", "< 9" 24 | s.add_dependency "vite_ruby", ">= 3.2.2", "~> 3.0" 25 | 26 | s.add_development_dependency "spring", "~> 2.1" 27 | 28 | s.files = Dir.glob("{lib,templates}/**/*") + %w[README.md CHANGELOG.md LICENSE.txt] 29 | end 30 | -------------------------------------------------------------------------------- /vite_ruby/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite_hanami/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite_padrino/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite_rails/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite-plugin-rails/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite-plugin-ruby/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite_plugin_legacy/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vite_rails_legacy/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/rails/example_engine/README.md: -------------------------------------------------------------------------------- 1 | # Vite Ruby ➕ Rails Engine 2 | 3 | An example on how to configure a Rails engine to use Vite Ruby. 4 | 5 | ## Configuration ⚙️ 6 | 7 | - Add `vite_rails` as a dependency in the engine `gemspec` 8 | - Run `bundle install` and `bundle exec vite install` in the engine directory 9 | - Check that the following files were added and configure them: 10 | - `config/vite.json`: Use a different `publicOutputDir` and `development.port` than the parent application to avoid conflicts 11 | - `vite.config.ts`: Should be using `vite-plugin-ruby` 12 | 13 | See `engine.rb` and ` application_helper.rb` in this example to add the rest 14 | of the setup. 15 | 16 | The `vite_manifest` must be overriden in the engine view helpers. 17 | 18 | ## Development 💻 19 | 20 | In order to enable HMR for assets inside the engine, run `bin/vite` inside the 21 | engine directory, and make sure you are rendering `vite_client_tag` in your 22 | engine views. 23 | 24 | Use a different `development.port` to prevent connecting to the same Vite dev 25 | server as the parent app. 26 | 27 | ## Deployment 🚀 28 | 29 | Run `bin/vite build` inside the engine directory to precompile assets. 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vite_ruby_monorepo", 3 | "version": "1.0.0", 4 | "private": true, 5 | "license": "MIT", 6 | "type": "module", 7 | "scripts": { 8 | "docs": "npm -C docs run dev", 9 | "docs:search": "npm -C docs run search", 10 | "release": "node scripts/release.cjs", 11 | "lint": "lint-staged", 12 | "postinstall": "husky install", 13 | "changelog": "node scripts/changelog.cjs" 14 | }, 15 | "devDependencies": { 16 | "@mussi/eslint-config": "^0.5.1", 17 | "@types/node": "^18", 18 | "chalk": "^4.1.2", 19 | "conventional-changelog-cli": "^2.2.2", 20 | "enquirer": "^2.3.6", 21 | "eslint": "^7.32.0", 22 | "execa": "^5.1.1", 23 | "husky": "^5.2.0", 24 | "lint-staged": "^10.5.4", 25 | "minimist": "^1.2.6", 26 | "semver": "^7.3.7", 27 | "typescript": "^4.7.4" 28 | }, 29 | "lint-staged": { 30 | "*.{js,ts,tsx,jsx,vue}": [ 31 | "eslint --fix" 32 | ], 33 | "*.rb": [ 34 | "bin/rubocop -A" 35 | ] 36 | }, 37 | "repository": { 38 | "type": "git", 39 | "url": "https://github.com/ElMassimo/vite_ruby" 40 | }, 41 | "homepage": "https://github.com/ElMassimo/vite_ruby" 42 | } 43 | -------------------------------------------------------------------------------- /vite-plugin-ruby/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Maximo Mussini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------