vite_rb 0.0.1.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +3 -0
- data/.dockerignore +22 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/build.yml +17 -0
- data/.gitignore +71 -0
- data/.ruby-version +1 -0
- data/.solargraph.yml +16 -0
- data/.standard.yml +11 -0
- data/CHANGELOG.md +65 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +258 -0
- data/Rakefile +39 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/examples/rails-without-webpack/.gitignore +34 -0
- data/examples/rails-without-webpack/.ruby-version +1 -0
- data/examples/rails-without-webpack/Gemfile +33 -0
- data/examples/rails-without-webpack/README.md +24 -0
- data/examples/rails-without-webpack/Rakefile +6 -0
- data/examples/rails-without-webpack/app/assets/config/manifest.js +2 -0
- data/examples/rails-without-webpack/app/assets/images/.keep +0 -0
- data/examples/rails-without-webpack/app/assets/stylesheets/application.css +15 -0
- data/examples/rails-without-webpack/app/assets/stylesheets/static_pages.scss +3 -0
- data/examples/rails-without-webpack/app/channels/application_cable/channel.rb +4 -0
- data/examples/rails-without-webpack/app/channels/application_cable/connection.rb +4 -0
- data/examples/rails-without-webpack/app/channels/chat_channel.rb +12 -0
- data/examples/rails-without-webpack/app/controllers/application_controller.rb +2 -0
- data/examples/rails-without-webpack/app/controllers/concerns/.keep +0 -0
- data/examples/rails-without-webpack/app/controllers/static_pages_controller.rb +4 -0
- data/examples/rails-without-webpack/app/helpers/application_helper.rb +2 -0
- data/examples/rails-without-webpack/app/helpers/static_pages_helper.rb +2 -0
- data/examples/rails-without-webpack/app/jobs/application_job.rb +7 -0
- data/examples/rails-without-webpack/app/mailers/application_mailer.rb +4 -0
- data/examples/rails-without-webpack/app/models/application_record.rb +3 -0
- data/examples/rails-without-webpack/app/models/concerns/.keep +0 -0
- data/examples/rails-without-webpack/app/snowpacker/assets/fake-asset.png +0 -0
- data/examples/rails-without-webpack/app/snowpacker/channels/consumer.js +5 -0
- data/examples/rails-without-webpack/app/snowpacker/channels/index.js +2 -0
- data/examples/rails-without-webpack/app/snowpacker/entrypoints/application.js +10 -0
- data/examples/rails-without-webpack/app/snowpacker/javascript/index.js +1 -0
- data/examples/rails-without-webpack/app/snowpacker/stylesheets/index.css +3 -0
- data/examples/rails-without-webpack/app/views/layouts/application.html.erb +15 -0
- data/examples/rails-without-webpack/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails-without-webpack/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails-without-webpack/app/views/static_pages/index.html.erb +2 -0
- data/examples/rails-without-webpack/bin/bundle +114 -0
- data/examples/rails-without-webpack/bin/rails +9 -0
- data/examples/rails-without-webpack/bin/rake +9 -0
- data/examples/rails-without-webpack/bin/setup +36 -0
- data/examples/rails-without-webpack/bin/spring +17 -0
- data/examples/rails-without-webpack/bin/yarn +9 -0
- data/examples/rails-without-webpack/config.ru +5 -0
- data/examples/rails-without-webpack/config/application.rb +19 -0
- data/examples/rails-without-webpack/config/boot.rb +4 -0
- data/examples/rails-without-webpack/config/cable.yml +10 -0
- data/examples/rails-without-webpack/config/credentials.yml.enc +1 -0
- data/examples/rails-without-webpack/config/database.yml +25 -0
- data/examples/rails-without-webpack/config/environment.rb +5 -0
- data/examples/rails-without-webpack/config/environments/development.rb +62 -0
- data/examples/rails-without-webpack/config/environments/production.rb +112 -0
- data/examples/rails-without-webpack/config/environments/test.rb +49 -0
- data/examples/rails-without-webpack/config/initializers/application_controller_renderer.rb +8 -0
- data/examples/rails-without-webpack/config/initializers/assets.rb +14 -0
- data/examples/rails-without-webpack/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails-without-webpack/config/initializers/content_security_policy.rb +31 -0
- data/examples/rails-without-webpack/config/initializers/cookies_serializer.rb +5 -0
- data/examples/rails-without-webpack/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/rails-without-webpack/config/initializers/inflections.rb +16 -0
- data/examples/rails-without-webpack/config/initializers/mime_types.rb +4 -0
- data/examples/rails-without-webpack/config/initializers/snowpacker.rb +41 -0
- data/examples/rails-without-webpack/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails-without-webpack/config/locales/en.yml +33 -0
- data/examples/rails-without-webpack/config/puma.rb +38 -0
- data/examples/rails-without-webpack/config/routes.rb +5 -0
- data/examples/rails-without-webpack/config/snowpacker/.browserslistrc +1 -0
- data/examples/rails-without-webpack/config/snowpacker/babel.config.js +76 -0
- data/examples/rails-without-webpack/config/snowpacker/postcss.config.js +12 -0
- data/examples/rails-without-webpack/config/snowpacker/snowpack.config.js +61 -0
- data/examples/rails-without-webpack/config/spring.rb +6 -0
- data/examples/rails-without-webpack/config/storage.yml +34 -0
- data/examples/rails-without-webpack/db/seeds.rb +7 -0
- data/examples/rails-without-webpack/lib/assets/.keep +0 -0
- data/examples/rails-without-webpack/lib/tasks/.keep +0 -0
- data/examples/rails-without-webpack/package.json +20 -0
- data/examples/rails-without-webpack/storage/.keep +0 -0
- data/examples/rails-without-webpack/test/application_system_test_case.rb +5 -0
- data/examples/rails-without-webpack/test/channels/application_cable/connection_test.rb +11 -0
- data/examples/rails-without-webpack/test/channels/chat_channel_test.rb +8 -0
- data/examples/rails-without-webpack/test/controllers/.keep +0 -0
- data/examples/rails-without-webpack/test/controllers/static_pages_controller_test.rb +8 -0
- data/examples/rails-without-webpack/test/fixtures/.keep +0 -0
- data/examples/rails-without-webpack/test/fixtures/files/.keep +0 -0
- data/examples/rails-without-webpack/test/helpers/.keep +0 -0
- data/examples/rails-without-webpack/test/integration/.keep +0 -0
- data/examples/rails-without-webpack/test/mailers/.keep +0 -0
- data/examples/rails-without-webpack/test/models/.keep +0 -0
- data/examples/rails-without-webpack/test/system/.keep +0 -0
- data/examples/rails-without-webpack/test/test_helper.rb +13 -0
- data/examples/rails-without-webpack/vendor/.keep +0 -0
- data/examples/rails-without-webpack/yarn.lock +7545 -0
- data/lib/tasks/rails.rake +31 -0
- data/lib/tasks/ruby.rake +21 -0
- data/lib/vite_rb.rb +25 -0
- data/lib/vite_rb/configuration.rb +56 -0
- data/lib/vite_rb/engine.rb +5 -0
- data/lib/vite_rb/env.rb +29 -0
- data/lib/vite_rb/generator.rb +81 -0
- data/lib/vite_rb/helpers.rb +51 -0
- data/lib/vite_rb/manifest.rb +40 -0
- data/lib/vite_rb/proxy.rb +35 -0
- data/lib/vite_rb/runner.rb +46 -0
- data/lib/vite_rb/templates/postcss.config.js +12 -0
- data/lib/vite_rb/templates/vite.config.js +71 -0
- data/lib/vite_rb/templates/vite.rb.tt +54 -0
- data/lib/vite_rb/templates/vite/channels/consumer.js +5 -0
- data/lib/vite_rb/templates/vite/channels/index.js +2 -0
- data/lib/vite_rb/templates/vite/entrypoints/application.js +10 -0
- data/lib/vite_rb/templates/vite/stylesheets/index.css +3 -0
- data/lib/vite_rb/utils.rb +55 -0
- data/lib/vite_rb/version.rb +5 -0
- data/package.json +25 -0
- data/package/src/index.js +0 -0
- data/vite_rb.gemspec +46 -0
- data/yarn.lock +1215 -0
- metadata +337 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4fdf3125edcc03c5871b2da86496aa4fb29f1915fbd9a617419231c3e49db2fd
|
4
|
+
data.tar.gz: 8d8d8aa54277af1f2943367e22955c1dca8fff13e5ec2d669901c1f668c4bca6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b14932e9e675dbbc27dfe0c8e50b590a882fa0a126e7dd2cc576bf67ba7f4581f64edc60fcc1a68d9fab6871f053b2b3274f0e62fd356b29002e8f24be8bbbe5
|
7
|
+
data.tar.gz: d2aee947f31f485c3d3fc6acc32690afaa86ee54dd4e333dae101f6f8198d0c87acea26abce0c905a8564b929bead29cc2ea25cdb564a44ff46a1ddbba47859a
|
data/.codeclimate.yml
ADDED
data/.dockerignore
ADDED
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: ParamagicDev
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: Run tests
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
os: [ubuntu, macos, windows]
|
9
|
+
ruby: [2.5, 2.6, 2.7, head]
|
10
|
+
runs-on: ${{ matrix.os }}-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
17
|
+
- run: bundle exec rake test
|
data/.gitignore
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
# rspec failure tracking
|
11
|
+
.rspec_status
|
12
|
+
|
13
|
+
public/
|
14
|
+
.cache/
|
15
|
+
|
16
|
+
log/
|
17
|
+
|
18
|
+
*node_modules*
|
19
|
+
|
20
|
+
.vscode/
|
21
|
+
tags
|
22
|
+
|
23
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
24
|
+
#
|
25
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
26
|
+
# or operating system, you probably want to add a global ignore instead:
|
27
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
28
|
+
|
29
|
+
# Ignore bundler config.
|
30
|
+
.bundle
|
31
|
+
|
32
|
+
# Ignore the default SQLite database.
|
33
|
+
examples/*/db/*.sqlite3
|
34
|
+
examples/*/db/*.sqlite3-journal
|
35
|
+
examples/*/db/*.sqlite3-*
|
36
|
+
|
37
|
+
# Ignore all logfiles and tempfiles.
|
38
|
+
examples/**/*log/
|
39
|
+
examples/**/*tmp
|
40
|
+
!examples/**/*log/.keep
|
41
|
+
!examples/**/*tmp/.keep
|
42
|
+
|
43
|
+
# Ignore pidfiles, but keep the directory.
|
44
|
+
examples/*/tmp/pids/*
|
45
|
+
!examples/*/tmp/pids/
|
46
|
+
!examples/*/tmp/pids/.keep
|
47
|
+
|
48
|
+
# Ignore uploaded files in development.
|
49
|
+
examples/*/storage/*
|
50
|
+
!examples/*/storage/.keep
|
51
|
+
|
52
|
+
examples/*/public/assets
|
53
|
+
examples/*/.byebug_history
|
54
|
+
|
55
|
+
# Ignore master key for decrypting credentials and more.
|
56
|
+
examples/*/config/master.key
|
57
|
+
|
58
|
+
examples/**/*tmp
|
59
|
+
examples/**/public/snowpacks
|
60
|
+
examples/**/node_modules
|
61
|
+
examples/**/yarn-error.log
|
62
|
+
examples/**/yarn-debug.log*
|
63
|
+
examples/**/.yarn-integrity
|
64
|
+
examples/**/snowpacks
|
65
|
+
|
66
|
+
test/**/*tmp
|
67
|
+
test/**/*storage
|
68
|
+
test/**/*node_modules
|
69
|
+
test/**/*yarn-error.log
|
70
|
+
package/dist
|
71
|
+
Gemfile.lock
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.2
|
data/.solargraph.yml
ADDED
data/.standard.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
fix: true # default: false
|
2
|
+
parallel: true # default: false
|
3
|
+
format: progress # default: Standard::Formatter
|
4
|
+
default_ignores: true # default: true
|
5
|
+
|
6
|
+
ignore: # default: []
|
7
|
+
- 'db/schema.rb'
|
8
|
+
- '**/*node_modules/**/*'
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'test/**/*':
|
11
|
+
- Layout/AlignHash
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
<a name="2020-07-27"></a>
|
2
|
+
### 2020-07-27
|
3
|
+
|
4
|
+
|
5
|
+
#### Bug Fixes
|
6
|
+
|
7
|
+
* move detect_port! into dev command ([b93f029](/../../commit/b93f029))
|
8
|
+
* add sourcing of docker.env ([66838ac](/../../commit/66838ac))
|
9
|
+
|
10
|
+
|
11
|
+
<a name="2020-07-26"></a>
|
12
|
+
### 2020-07-26
|
13
|
+
|
14
|
+
|
15
|
+
#### Features
|
16
|
+
|
17
|
+
* add postcss packages ([783adf8](/../../commit/783adf8))
|
18
|
+
* allow for an encapsulated postcss & babel config ([f95e15a](/../../commit/f95e15a))
|
19
|
+
* add @snowpack/babel-plugin-package-import for transforming imports ([596df4a](/../../commit/596df4a))
|
20
|
+
* add postcss and babel config attrs to configuration ([f0d51b6](/../../commit/f0d51b6))
|
21
|
+
* add @snowpack/plugin-babel to generator ([3a7d872](/../../commit/3a7d872))
|
22
|
+
* generate configs with generator ([1906a31](/../../commit/1906a31))
|
23
|
+
* add babel and postcss configs to templates ([a0b0ec4](/../../commit/a0b0ec4))
|
24
|
+
|
25
|
+
|
26
|
+
#### Bug Fixes
|
27
|
+
|
28
|
+
* **config**
|
29
|
+
* fix issue with configuration.rb, generate config ([3d6a8f1](/../../commit/3d6a8f1))
|
30
|
+
|
31
|
+
* **generator**
|
32
|
+
* now properly generates files ([ba62564](/../../commit/ba62564))
|
33
|
+
|
34
|
+
* use the preset node_env prior to setting one. ([abe788a](/../../commit/abe788a))
|
35
|
+
* Env now respects user set env vars ([588b41f](/../../commit/588b41f))
|
36
|
+
|
37
|
+
|
38
|
+
<a name="2020-07-24"></a>
|
39
|
+
### 2020-07-24
|
40
|
+
|
41
|
+
|
42
|
+
#### Features
|
43
|
+
|
44
|
+
* add an example of using stylesheet link tags ([889f241](/../../commit/889f241))
|
45
|
+
* add a mount directory configuration ([c8556d7](/../../commit/c8556d7))
|
46
|
+
* add a compile rake task ([607ef29](/../../commit/607ef29))
|
47
|
+
* updating templates ([e126948](/../../commit/e126948))
|
48
|
+
* rewrite snowpack.config to js format ([e6f89aa](/../../commit/e6f89aa))
|
49
|
+
* allow users to define a hostname and port ([95ff03b](/../../commit/95ff03b))
|
50
|
+
* add rack-proxy for proxy requests ([8635324](/../../commit/8635324))
|
51
|
+
* add snowpacks to example directory ([bb3f1e9](/../../commit/bb3f1e9))
|
52
|
+
* have the runner specify a node_env ([5f97e9a](/../../commit/5f97e9a))
|
53
|
+
* modify generators and update readme ([a305177](/../../commit/a305177))
|
54
|
+
* Add a prior-to-install directory ([fbca36d](/../../commit/fbca36d))
|
55
|
+
* add docker ([945d27b](/../../commit/945d27b))
|
56
|
+
|
57
|
+
#### Bug Fixes
|
58
|
+
|
59
|
+
* gitignore to ignore node_modules ([e1ee78d](/../../commit/e1ee78d))
|
60
|
+
* remove parcel-bundler, remove .travis.yml ([08ecb2a](/../../commit/08ecb2a))
|
61
|
+
|
62
|
+
* **gitignore**
|
63
|
+
* ignore tags ([890ce35](/../../commit/890ce35))
|
64
|
+
|
65
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Michał Darda
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
# Vite
|
2
|
+
|
3
|
+
## WORK IN PROGRESS
|
4
|
+
|
5
|
+
If you would like to help support the future of this project,
|
6
|
+
please consider sponsoring me so I can keep a regular stream
|
7
|
+
of updates and fixes to this project.
|
8
|
+
|
9
|
+
https://github.com/sponsors/ParamagicDev
|
10
|
+
|
11
|
+
Please note, that this project is still in it's infancy. Feel free to
|
12
|
+
file bug reports, issues, and feature requests.
|
13
|
+
|
14
|
+
[![Gem Version](https://badge.fury.io/rb/vite_rb.svg)](https://badge.fury.io/rb/vite_rb)
|
15
|
+
|
16
|
+
<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/b88ac1a56d868d4f23d5/maintainability)](https://codeclimate.com/github/ParamagicDev/vite_rb/maintainability) -->
|
17
|
+
|
18
|
+
This gem integrates the [Vite](https://vitejs.dev/) JS module bundler into
|
19
|
+
your Rails / Ruby application. It is inspired by gems such as
|
20
|
+
[breakfast](https://github.com/devlocker/breakfast) /
|
21
|
+
[webpacker](https://github.com/rails/webpacker) and this project started
|
22
|
+
as a fork of
|
23
|
+
[Vite](https://github.com/ParamagicDev/vite_rb).
|
24
|
+
|
25
|
+
This is not meant to be a 1:1 replacement of Webpacker. ViteRb is
|
26
|
+
actually just a wrapper around Vite using Rake / Thor and as a result can
|
27
|
+
be used with any Rack based framework. Vite comes with first class
|
28
|
+
support for Rails including Generators and autoloaded helpers.
|
29
|
+
|
30
|
+
## How is Vite different?
|
31
|
+
|
32
|
+
Vite is unbundled during development to eliminate compilation
|
33
|
+
times. Asset requests are cached with 304 headers. Bundling is saved for the final build process due to waterfall
|
34
|
+
network requests that still cause some issues in production and can
|
35
|
+
cause significant slowdown.
|
36
|
+
|
37
|
+
Vite uses the native ESM module spec. ESM Modules are fast,
|
38
|
+
lightweight, and natively supported by all newer browsers ("evergreen browsers")
|
39
|
+
For more reading on ESM modules, check out this link:
|
40
|
+
|
41
|
+
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
42
|
+
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
Add this line to your application's Gemfile:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'vite_rb', git: "https://github.com/ParamagicDev/vite_rb"
|
50
|
+
```
|
51
|
+
|
52
|
+
### With Rails
|
53
|
+
|
54
|
+
```bash
|
55
|
+
rails vite:init
|
56
|
+
```
|
57
|
+
|
58
|
+
Which will install your yarn packages, create an initializer file, add config files, and create an `app/vite` directory similar to Webpacker.
|
59
|
+
|
60
|
+
#### Tasks
|
61
|
+
|
62
|
+
```bash
|
63
|
+
rails vite:dev # starts a dev server
|
64
|
+
rails vite:build # builds for production (is hooked onto
|
65
|
+
precompile)
|
66
|
+
rails assets:precompile # will build vite and the asset pipeline
|
67
|
+
```
|
68
|
+
|
69
|
+
#### Existing Rails app
|
70
|
+
|
71
|
+
When working with a new Rails app, it is important to switch any webpack
|
72
|
+
`require` statements to ESM-based `import`. For example, consider the
|
73
|
+
following javascript file:
|
74
|
+
|
75
|
+
```diff
|
76
|
+
// app/javascript/packs/application.js
|
77
|
+
|
78
|
+
- // Webpack
|
79
|
+
- require("@rails/ujs").start()
|
80
|
+
- require("turbolinks").start()
|
81
|
+
- require("@rails/activestorage").start()
|
82
|
+
- require("channels")
|
83
|
+
-
|
84
|
+
+ // app/vite/entrypoints/applications.js
|
85
|
+
+ import "@rails/ujs" // Autostarts
|
86
|
+
+ import Turbolinks from "turbolinks"
|
87
|
+
+ import ActiveStorage from "@rails/activestorage"
|
88
|
+
+ import "../channels"
|
89
|
+
+
|
90
|
+
+ Turbolinks.start()
|
91
|
+
+ ActiveStorage.start()
|
92
|
+
```
|
93
|
+
|
94
|
+
You may notice a `require.context` statement in your javascript to load
|
95
|
+
`channels`. This runs via Node and is not browser compatible. Vite comes
|
96
|
+
with a glob import syntax, you can read about it here: @TODO
|
97
|
+
|
98
|
+
```diff
|
99
|
+
// app/javascript/channels/index.js
|
100
|
+
|
101
|
+
// Load all the channels within this directory and all subdirectories.
|
102
|
+
// Channel files must be named *_channel.js.
|
103
|
+
|
104
|
+
- const channels = require.context('.', true, /_channel\.js$/)
|
105
|
+
- channels.keys().forEach(channels)
|
106
|
+
// @TODO
|
107
|
+
```
|
108
|
+
|
109
|
+
## File Structure
|
110
|
+
|
111
|
+
Vite makes some assumptions about your file paths to provide
|
112
|
+
helper methods.
|
113
|
+
|
114
|
+
```bash
|
115
|
+
tree -L 2 app/vite
|
116
|
+
|
117
|
+
app/vite/
|
118
|
+
├── assets/
|
119
|
+
│ └── picture.png
|
120
|
+
├── channels/
|
121
|
+
│ ├── consumer.js
|
122
|
+
│ └── index.js
|
123
|
+
├── entrypoints/
|
124
|
+
│ └── application.js
|
125
|
+
├── javascript/
|
126
|
+
│ └── index.js
|
127
|
+
└── stylesheets/
|
128
|
+
└── index.css
|
129
|
+
```
|
130
|
+
|
131
|
+
Which upon build will output to look like this:
|
132
|
+
|
133
|
+
```bash
|
134
|
+
tree -L 1 public/Vites
|
135
|
+
|
136
|
+
public/vite/
|
137
|
+
├── assets/
|
138
|
+
├── channels/
|
139
|
+
├── entrypoints/
|
140
|
+
├── javascript/
|
141
|
+
├── css/
|
142
|
+
```
|
143
|
+
|
144
|
+
## Helpers
|
145
|
+
|
146
|
+
### Generic Helper
|
147
|
+
|
148
|
+
`<%= vite_path %>` will return the value of
|
149
|
+
`Vite.config.output_dir`
|
150
|
+
|
151
|
+
### Assets
|
152
|
+
|
153
|
+
Assets can be accessed via `<%= vite_asset_path("name", **options) %>` and accepts all
|
154
|
+
the same params as [#asset_path](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path)
|
155
|
+
|
156
|
+
### Channels
|
157
|
+
|
158
|
+
Channels have no special helper.
|
159
|
+
|
160
|
+
### Packs
|
161
|
+
|
162
|
+
Packs can be accessed via:
|
163
|
+
|
164
|
+
`<%= javascript_vite_tag %>` and works the same as
|
165
|
+
[`#javascript_include_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-javascript_include_tag)
|
166
|
+
|
167
|
+
`packs` are your "entrypoints" and where files get bundled to, very
|
168
|
+
similar to Webpacker.
|
169
|
+
|
170
|
+
### Javascript
|
171
|
+
|
172
|
+
Javascript files have no special helper.
|
173
|
+
|
174
|
+
### Stylesheets
|
175
|
+
|
176
|
+
Stylesheets can be accessed via:
|
177
|
+
|
178
|
+
`<%= stylesheet_vite_tag %>` and works just like
|
179
|
+
[`#stylesheet_link_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-stylesheet_link_tag).
|
180
|
+
I recommend importing your css in your `packs` file if you plan on
|
181
|
+
changing it to support HMR.
|
182
|
+
|
183
|
+
### HMR
|
184
|
+
|
185
|
+
To enable HMR for your vite assets, put the following in the `<head>` of
|
186
|
+
your document:
|
187
|
+
|
188
|
+
`<%= vite_hmr_tag %>`
|
189
|
+
|
190
|
+
## Configuration
|
191
|
+
|
192
|
+
After running generator, the configuration file can be found in
|
193
|
+
`config/initializers/vite.rb`
|
194
|
+
|
195
|
+
In addition, all related `vite.config.js`, and
|
196
|
+
`postcss.config.js` can all be found in the `config/vite`
|
197
|
+
directory.
|
198
|
+
|
199
|
+
## Production
|
200
|
+
|
201
|
+
ViteRb hooks up to the `rails assets:precompile` and `rails
|
202
|
+
assets:clobber`, so no special setup is required.
|
203
|
+
|
204
|
+
You can start vite_rb's compilation process manually by running
|
205
|
+
|
206
|
+
```bash
|
207
|
+
rails vite:compile
|
208
|
+
|
209
|
+
# OR
|
210
|
+
|
211
|
+
rails vite:build
|
212
|
+
```
|
213
|
+
|
214
|
+
|
215
|
+
## Examples
|
216
|
+
|
217
|
+
Examples can be found in the [/examples](/examples) directory.
|
218
|
+
|
219
|
+
## Converting from Webpack to Snowpack
|
220
|
+
|
221
|
+
- `require.context()` is not currently supported
|
222
|
+
|
223
|
+
Instead, use the glob syntax from [Vite](https://vitejs.dev)
|
224
|
+
|
225
|
+
## Issues
|
226
|
+
|
227
|
+
Not all packages may be compatible with Vite. Please check
|
228
|
+
[skypack.dev](https://skypack.dev) for ESM-compatible packages.
|
229
|
+
|
230
|
+
## Changelog
|
231
|
+
|
232
|
+
See [CHANGELOG.md](https://github.com/ParamagicDev/vite_rb/blob/master/CHANGELOG.md)
|
233
|
+
|
234
|
+
## Contributing
|
235
|
+
|
236
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ParamagicDev/vite_rb.
|
237
|
+
|
238
|
+
## License
|
239
|
+
|
240
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
241
|
+
|
242
|
+
## Roadmap
|
243
|
+
|
244
|
+
- [ ] Add default file structure with init
|
245
|
+
|
246
|
+
- [x] Support require.context (Glob importing supported by Vite)
|
247
|
+
|
248
|
+
- [ ] Reading from production manifest
|
249
|
+
|
250
|
+
- [ ] Parity with Webpacker helper methods
|
251
|
+
|
252
|
+
- [ ] Add documentation / installation on Stimulus
|
253
|
+
|
254
|
+
- [ ] Create an npm package to read a default config from and pin Vite versions
|
255
|
+
|
256
|
+
- [ ] Add in End-to-end testing to confirm everything works as intended.
|
257
|
+
|
258
|
+
- [ ] Make the config environment from NPM in Typescript so users can import types for good completion.
|