-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add upgrade command and additionalEntrypoints setting (#116)
BREAKING CHANGE: vite_asset_path now requires an explicit path relative to the sourceCodeDir for nested directories. Example: vite_asset_path 'entrypoints/images/logo.png' BREAKING CHANGE: sourceCodeDir is now the Vite.js root BREAKING CHANGE: Manifest names are now relative to the sourceCodeDir to prevent collisions
- Loading branch information
Showing
117 changed files
with
4,502 additions
and
3,986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd vite-plugin-ruby | ||
|
||
pnpm install | ||
pnpm build | ||
pnpm example:build | ||
|
||
rm -Rf ../test/test_app/public/vite-production | ||
cp -R example/public/vite ../test/test_app/public/vite-production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[tag helpers]: /guide/rails.html#tag-helpers-%F0%9F%8F%B7 | ||
[additionalEntrypoints]: /config/#additionalentrypoints | ||
[entrypointsDir]: /config/#entrypointsdir | ||
[sourceCodeDir]: /config/#sourcecodedir | ||
[watchAdditionalPaths]: /config/#watchadditionalpaths | ||
[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 | ||
[config.json]: /config/#shared-configuration-file-📄 | ||
[sidecar assets]: https://viewcomponent.org/guide/sidecar_assets.html | ||
[viewcomponent]: https://viewcomponent.org/ | ||
[glob imports]: https://vitejs.dev/guide/features.html#glob-import | ||
|
||
# Advanced Usage | ||
|
||
This section discusses settings that most projects don't need to configure | ||
explicitly. | ||
|
||
## Additional Entrypoints | ||
|
||
The <kbd>[additionalEntrypoints]</kbd> setting added in `3.0.0` allows you to | ||
configure additional entries that are located outside the <kbd>[entrypointsDir]</kbd>. | ||
|
||
By default, it's configured to: `["~/{assets,fonts,icons,images}/**/*"]`, which | ||
enables bundling and referencing these files with [tag helpers]: | ||
|
||
```ruby | ||
vite_asset_path 'images/logo.svg' # app/frontend/images/logo.svg | ||
``` | ||
|
||
If you would like to opt out from bundling these files, [configure it][config.json] as: | ||
|
||
```json | ||
"additionalEntrypoints": [] | ||
``` | ||
|
||
## Bundling files outside sourceCodeDir | ||
|
||
When using a library such as [`ViewComponent`][viewcomponent], it can be | ||
convenient to group JS and CSS files within each component folder, which is called [sidecar assets]. | ||
|
||
There are a few options to achieve this, each with their pros and cons. | ||
|
||
:::tip Required | ||
Make sure to add `app/components/**/*` to <kbd>[watchAdditionalPaths]</kbd>, to | ||
ensure the build is triggered when any of the component files changes. | ||
::: | ||
|
||
### Import every component | ||
|
||
The simplest option is to leverage [glob imports] to import all components in a | ||
single entrypoint, which is suitable for cases where there are few components, | ||
or when all components should be registered in all pages. | ||
|
||
```js | ||
// app/frontend/entrypoints/application.js | ||
import.meta.globEager('../../components/**/*_component.js') | ||
``` | ||
|
||
Any files imported from each `.js` file will be bundled as well. | ||
|
||
### One entrypoint per component | ||
|
||
To bundle each component independently, configure <kbd>[additionalEntrypoints]</kbd>: | ||
|
||
```json | ||
"additionalEntrypoints": [ | ||
"app/components/**/*_component.{js,ts}", | ||
"~/{assets,fonts,icons,images}/**/*" | ||
] | ||
``` | ||
|
||
and then reference them as needed in views or partials: | ||
|
||
```erb | ||
<%= vite_javascript_tag '/app/components/comment_component' %> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.