ElMassimo/vite_ruby

View on GitHub
docs/src/guide/migrating-from-v2.md

Summary

Maintainability
Test Coverage
[tag helpers]: /guide/rails.html#tag-helpers-%F0%9F%8F%B7
[additionalEntrypoints]: /config/#additionalentrypoints
[entrypointsDir]: /config/#entrypointsdir
[sourceCodeDir]: /config/#sourcecodedir
[entrypoints]: /guide/development.html#entrypoints-โคต%EF%B8%8F
[tag helpers]: /guide/development.html#tag-helpers-๐Ÿท
[CLI Command]: /guide/development.html#cli-commands-โŒจ%EF%B8%8F
[vite-plugin-ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-ruby

# Migrating to Vite Ruby v3

This section is intended to guide early adopters to upgrade from Vite Rails v2
to v3.

## New Features โœจ

### Safer Upgrades

<kbd>bin/vite upgrade</kbd> is a new [CLI command] to easily upgrade any
Vite Ruby gems you are using, as well as the <kbd>[vite-plugin-ruby]</kbd> npm
package, to compatible versions.

### Additional Entrypoints

<kbd>[additionalEntrypoints]</kbd> is a new configuration option to specify [entrypoints].

By default it adds <code><kbd>[sourceCodeDir]</kbd>/{assets,fonts,icons,images}/**/*</code>, so you can now reference these files using [tag helpers] instead of having to place them inside <kbd>[entrypointsDir]</kbd>.

```ruby
vite_asset_path 'images/logo.svg' # app/frontend/images/logo.svg
```

## Breaking Changes ๐Ÿงจ

### Nested entrypoints paths must be explicit

Any paths without a parent dir will be resolved to the <kbd>[entrypointsDir]</kbd>:

```ruby
vite_javascript_tag 'application' # entrypoints/application.js
```

But for entrypoints in a nested directory in <kbd>[entrypointsDir]</kbd>,
the path must now be explicit:

<div class="language-">
  <pre>
<code>app/frontend: <kbd><a href="/config/#sourcecodedir">sourceCodeDir</a></kbd>
  โ””โ”€โ”€ entrypoints: <kbd><a href="/config/#entrypointsdir">entrypointsDir</a></kbd>
      โ”œโ”€โ”€ nested:
      โ”‚   โ””โ”€โ”€ application.js
      โ””โ”€โ”€ images
          โ””โ”€โ”€ logo.svg</code>
</pre>
</div>

```ruby
โŒ vite_javascript_tag 'nested/application'
โœ… vite_javascript_tag 'entrypoints/nested/application'

โŒ vite_asset_path 'images/logo.svg'
โœ… vite_asset_path 'entrypoints/images/logo.svg'
```

For assets located inside <kbd>[entrypointsDir]</kbd> there is now a [better
solution][additionalEntrypoints] as described in the previous section, which is
to place assets in one of the default <kbd>[additionalEntrypoints]</kbd> dirs:

```diff
- app/frontend/entrypoints/images/logo.svg
+ app/frontend/images/logo.svg
``` 

<div class="language-">
  <pre>
<code>app/frontend: <kbd><a href="/config/#sourcecodedir">sourceCodeDir</a></kbd>
  โ”œโ”€โ”€ entrypoints: <kbd><a href="/config/#entrypointsdir">entrypointsDir</a></kbd>
  โ”‚   โ””โ”€โ”€ nested:
  โ”‚       โ””โ”€โ”€ application.js
  โ””โ”€โ”€ images
      โ””โ”€โ”€ logo.svg</code>
</pre>
</div>

```ruby
โœ… vite_javascript_tag 'entrypoints/nested/application'
โœ… vite_asset_path 'images/logo.svg'
```

<br/><br/><br/><br/><br/><br/><br/>