rails_vite 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0857c5ff94e3b683d91dc9514d94f03669cbc470a83690ab1952f152ec339f11'
4
- data.tar.gz: c8c67fc040f4050365e8a16feb3aa18bf5ed35bf5c75e2174a7b1235830991c1
3
+ metadata.gz: e0866cfdef70a06feb58cd405f2cdd7c7f9ddcb097871ac6fb272041b00083e9
4
+ data.tar.gz: b9ddef44f6b0e08d780f034a6927cb778f4ffd2a9435ccbdac1aa24e1e989251
5
5
  SHA512:
6
- metadata.gz: 3dbd780374483c13a7847076fe22cd64bbfe5852cdcbd003340ed1de8be7d883da3baef5f8ffeab4f46be18ee39f25c21a22a5b2977250b96b8078a18955635b
7
- data.tar.gz: c5550e0498ddfbea0f37c562874123efb319a2db047164a6cf4809397ff17ebfb4a5a0628ee53457f1739fad01122048526354f37a0ae40a472467028f2aab4b
6
+ metadata.gz: bea54a2fe1632fb4f4abe14e5bb0d5f8acd4fae71c24107b667dce65eeb144744e62fada3fff4c5eceaccbd5f70ab749dbd555fcdf0f109b39789abc29aa13f4
7
+ data.tar.gz: 01bd405f1b316d45814e8df8fbf18d8ab6f00169620262784a4bc41ca4964b6bf0ea6a8a1dc18b697cb72f6154563cd16060a1f3546cdb90df68e038c20702bd
data/CHANGELOG.md CHANGED
@@ -5,7 +5,28 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog],
6
6
  and this project adheres to [Semantic Versioning].
7
7
 
8
- ## [Unreleased]
8
+ ## [0.2.1] - 2026-03-17
9
+
10
+ ### Added
11
+
12
+ - Vite 8 (Rolldown) compatibility — support `rolldownOptions` alongside `rollupOptions` ([@skryukov])
13
+ - Test mode isolation — build to `public/vite-test/` in test mode so test builds don't clobber dev/prod assets ([@skryukov])
14
+ - Define `assets:precompile` and `assets:clobber` rake tasks when no asset pipeline is present ([@skryukov])
15
+
16
+ ### Fixed
17
+
18
+ - Fix `?url` imports and asset references pointing to Rails server instead of Vite dev server ([@skryukov])
19
+ - Fix embedded Vite instances (Storybook) overwriting dev stubs in jsbundling mode ([@skryukov])
20
+
21
+ ## [0.2.0] - 2026-03-11
22
+
23
+ ### Added
24
+
25
+ - jsbundling mode — use Vite as a bundler with `jsbundling-rails` and Propshaft, no gem required ([@skryukov])
26
+
27
+ ### Fixed
28
+
29
+ - `vite_asset_path` now works in development ([@skryukov])
9
30
 
10
31
  ## [0.1.2] - 2026-03-08
11
32
 
@@ -35,7 +56,9 @@ and this project adheres to [Semantic Versioning].
35
56
 
36
57
  [@skryukov]: https://github.com/skryukov
37
58
 
38
- [Unreleased]: https://github.com/skryukov/rails_vite/compare/v0.1.2...HEAD
59
+ [Unreleased]: https://github.com/skryukov/rails_vite/compare/v0.2.1...HEAD
60
+ [0.2.1]: https://github.com/skryukov/rails_vite/compare/v0.2.0...v0.2.1
61
+ [0.2.0]: https://github.com/skryukov/rails_vite/compare/v0.1.2...v0.2.0
39
62
  [0.1.2]: https://github.com/skryukov/rails_vite/compare/v0.1.1...v0.1.2
40
63
  [0.1.1]: https://github.com/skryukov/rails_vite/compare/v0.1.0...v0.1.1
41
64
  [0.1.0]: https://github.com/skryukov/rails_vite/commits/v0.1.0
data/README.md CHANGED
@@ -16,6 +16,7 @@ Vite integration for Rails, inspired by [Laravel's Vite plugin](https://laravel.
16
16
  - [Testing the Build](#testing-the-build)
17
17
  - [Custom Paths](#custom-paths)
18
18
  - [Rake Tasks](#rake-tasks)
19
+ - [jsbundling Mode](#jsbundling-mode)
19
20
  - [Migrating from vite_rails](#migrating-from-vite_rails)
20
21
  - [Contributing](#contributing)
21
22
  - [License](#license)
@@ -141,7 +142,7 @@ Use `import.meta.glob` in your entry point to include assets in the Vite manifes
141
142
 
142
143
  ```js
143
144
  // app/javascript/application.js
144
- import.meta.glob(['../assets/images/**']);
145
+ import.meta.glob(['../assets/images/**'], { eager: true });
145
146
  ```
146
147
 
147
148
  Then reference them in views:
@@ -172,10 +173,10 @@ export default defineConfig({
172
173
  | `input` | auto-detected | Entry point(s). If `sourceDir/entrypoints/` exists, all files in it are used. Otherwise, detects `application.{js,ts,jsx,tsx}` in `sourceDir` |
173
174
  | `sourceDir` | `'app/javascript'` | Source directory. Short names are prefixed with this. Also sets the `@` import alias |
174
175
  | `ssr` | — | SSR entry point |
175
- | `ssrOutputDirectory` | `'ssr'` | SSR output directory |
176
+ | `ssrOutDir` | `'ssr'` | SSR output directory |
176
177
  | `devMetaFile` | `'tmp/rails-vite.json'` | Dev metadata file path |
177
- | `buildDirectory` | `'vite'` | Build output subdirectory inside `public/` |
178
- | `publicDirectory` | `'public'` | Public directory |
178
+ | `buildDir` | `'vite'` | Build output subdirectory inside `public/` |
179
+ | `publicDir` | `'public'` | Public directory |
179
180
  | `refresh` | `true` | Paths to watch for full-page reload. `true` watches `app/views/**` and `app/helpers/**` |
180
181
 
181
182
  ### Multiple Entry Points
@@ -251,7 +252,7 @@ export default defineConfig({
251
252
 
252
253
  ## SSR
253
254
 
254
- Set `ssr` to the entry point used for server-side rendering. When you run `npx vite build --ssr`, the plugin uses this as the input and outputs to the `ssrOutputDirectory` (default: `ssr/`).
255
+ Set `ssr` to the entry point used for server-side rendering. When you run `npx vite build --ssr`, the plugin uses this as the input and outputs to the `ssrOutDir` (default: `ssr/`).
255
256
 
256
257
  ```typescript
257
258
  rails({
@@ -317,6 +318,80 @@ Defaults match the plugin defaults — no config needed if you follow convention
317
318
  `vite:build` hooks into `assets:precompile` and `test:prepare` automatically. Skip with `SKIP_VITE_BUILD=1`.
318
319
 
319
320
 
321
+ ## jsbundling Mode
322
+
323
+ If you're using [`jsbundling-rails`](https://github.com/rails/jsbundling-rails) with Propshaft and want Vite as your bundler, you don't need the `rails_vite` gem — just the npm package:
324
+
325
+ ```bash
326
+ npm install -D rails-vite-plugin vite
327
+ ```
328
+
329
+ ```typescript
330
+ // vite.config.ts
331
+ import { defineConfig } from 'vite';
332
+ import jsbundling from 'rails-vite-plugin/jsbundling';
333
+
334
+ export default defineConfig({
335
+ plugins: [
336
+ jsbundling(),
337
+ ],
338
+ });
339
+ ```
340
+
341
+ **How it works:** In production, Vite builds to `public/assets/` and copies entry files to `app/assets/builds/` so Propshaft can serve them via `javascript_include_tag` and `stylesheet_link_tag`. In development, the plugin writes stub files to `app/assets/builds/` that redirect the browser to Vite's dev server for HMR.
342
+
343
+ ### jsbundling Options
344
+
345
+ | Option | Default | Description |
346
+ |--------|---------|-------------|
347
+ | `input` | auto-detected | Entry point(s). If `sourceDir/entrypoints/` exists, all files in it are used. Otherwise, detects `application.{js,ts,jsx,tsx}` in `sourceDir` |
348
+ | `sourceDir` | `'app/javascript'` | Source directory. Short names are prefixed with this. Also sets the `@` import alias |
349
+ | `assetPipelineDir` | `'app/assets/builds'` | Directory where Propshaft/Sprockets picks up entry files |
350
+ | `outputDir` | `'public/assets'` | Public directory for the full Vite build output |
351
+ | `ssr` | — | SSR entry point. String or `{ entry, outDir }` |
352
+ | `refresh` | — | Paths to watch for full-page reload. `true` watches `app/views/**` and `app/helpers/**` |
353
+ | `devMetaFile` | `'tmp/rails-vite.json'` | Dev metadata file path. Set to `false` to disable |
354
+
355
+ ### Replacing esbuild
356
+
357
+ In your `Procfile.dev`, replace the esbuild command:
358
+
359
+ ```
360
+ web: bin/rails server -p 3000
361
+ -js: yarn build --watch
362
+ +vite: npx vite
363
+ ```
364
+
365
+ CSS and JS entries in `app/javascript/entrypoints/` are auto-discovered. Both `javascript_include_tag` and `stylesheet_link_tag` work unchanged — Propshaft resolves them from `app/assets/builds/` as before.
366
+
367
+ ### Frameworks
368
+
369
+ React and Vue work the same as in the standard plugin — add the framework plugin before `jsbundling()`:
370
+
371
+ ```typescript
372
+ import { defineConfig } from 'vite';
373
+ import jsbundling from 'rails-vite-plugin/jsbundling';
374
+ import react from '@vitejs/plugin-react';
375
+
376
+ export default defineConfig({
377
+ plugins: [
378
+ react(),
379
+ jsbundling(),
380
+ ],
381
+ });
382
+ ```
383
+
384
+ ### Upgrading to rails_vite
385
+
386
+ To switch from jsbundling mode to the full `rails_vite` gem:
387
+
388
+ 1. Add `gem "rails_vite"` to your Gemfile and `bundle install`
389
+ 2. Change the import in `vite.config.ts` from `rails-vite-plugin/jsbundling` to `rails-vite-plugin`
390
+ 3. Replace `javascript_include_tag` / `stylesheet_link_tag` with `vite_tags` in your layouts
391
+ 4. Remove `jsbundling-rails` from your Gemfile
392
+
393
+ In development, jsbundling mode writes `tmp/rails-vite.json` — the same file the `rails_vite` gem reads. You can add the gem and verify `vite_tags` works in dev before deploying.
394
+
320
395
  ## Migrating from vite_rails
321
396
 
322
397
  ### 1. Swap dependencies
@@ -330,7 +405,7 @@ Defaults match the plugin defaults — no config needed if you follow convention
330
405
  ```json
331
406
  // package.json — replace vite-plugin-ruby with rails-vite-plugin
332
407
  - "vite-plugin-ruby": "^5.1.1"
333
- + "rails-vite-plugin": "^0.1.0"
408
+ + "rails-vite-plugin": "^0.2.0"
334
409
  ```
335
410
 
336
411
  ### 2. Replace `vite.config.ts`
@@ -2,18 +2,22 @@ module RailsVite
2
2
  class Config
3
3
  META_FILENAME = "rails-vite.json"
4
4
 
5
- attr_writer :dev_meta_path, :manifest_path, :asset_prefix, :auto_build
5
+ attr_writer :dev_meta_path, :manifest_path, :asset_prefix, :auto_build, :build_dir
6
6
 
7
7
  def dev_meta_path
8
8
  @dev_meta_path || Rails.root.join("tmp", META_FILENAME)
9
9
  end
10
10
 
11
+ def build_dir
12
+ @build_dir || (Rails.env.test? ? "vite-test" : "vite")
13
+ end
14
+
11
15
  def manifest_path
12
- @manifest_path || Rails.root.join("public/vite/manifest.json")
16
+ @manifest_path || Rails.root.join("public", build_dir, "manifest.json")
13
17
  end
14
18
 
15
19
  def asset_prefix
16
- @asset_prefix || "/vite"
20
+ @asset_prefix || "/#{build_dir}"
17
21
  end
18
22
 
19
23
  def source_dir
@@ -30,6 +34,7 @@ module RailsVite
30
34
  end
31
35
 
32
36
  def dev_server_running?
37
+ return false if Rails.env.test?
33
38
  !!dev_server_url
34
39
  end
35
40
 
@@ -27,7 +27,14 @@ module RailsVite
27
27
  end
28
28
 
29
29
  def vite_asset_path(name)
30
- vite_asset_url(RailsVite.manifest.path_for(name))
30
+ config = RailsVite.config
31
+ resolved = resolve_vite_entry(name, config.source_dir, nil)
32
+
33
+ if config.dev_server_running?
34
+ "#{config.dev_server_url}/#{resolved}"
35
+ else
36
+ vite_asset_url(RailsVite.manifest.path_for(resolved))
37
+ end
31
38
  end
32
39
 
33
40
  def vite_image_tag(name, **options)
@@ -31,7 +31,9 @@ module RailsVite
31
31
  end
32
32
 
33
33
  def build_command
34
- command_for(:build)
34
+ cmd = command_for(:build)
35
+ cmd += " --mode test" if Rails.env.test?
36
+ cmd
35
37
  end
36
38
 
37
39
  def tool
@@ -1,3 +1,3 @@
1
1
  module RailsVite
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -20,10 +20,24 @@ namespace :vite do
20
20
  end
21
21
 
22
22
  unless ENV["SKIP_VITE_BUILD"]
23
- %w[assets:precompile test:prepare spec:prepare db:test:prepare].each do |t|
24
- Rake::Task[t].enhance(["vite:build"]) if Rake::Task.task_defined?(t)
25
- break if %w[test:prepare spec:prepare].include?(t) && Rake::Task.task_defined?(t)
23
+ if Rake::Task.task_defined?("assets:precompile")
24
+ Rake::Task["assets:precompile"].enhance(["vite:build"])
25
+ else
26
+ desc "Compile assets"
27
+ Rake::Task.define_task("assets:precompile" => "vite:build")
26
28
  end
27
29
 
28
- Rake::Task["assets:clobber"].enhance(["vite:clobber"]) if Rake::Task.task_defined?("assets:clobber")
30
+ if Rake::Task.task_defined?("assets:clobber")
31
+ Rake::Task["assets:clobber"].enhance(["vite:clobber"])
32
+ else
33
+ desc "Remove compiled assets"
34
+ Rake::Task.define_task("assets:clobber" => "vite:clobber")
35
+ end
36
+
37
+ %w[test:prepare spec:prepare db:test:prepare].each do |t|
38
+ if Rake::Task.task_defined?(t)
39
+ Rake::Task[t].enhance(["vite:build"])
40
+ break
41
+ end
42
+ end
29
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_vite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov