vite_rails 1.0.11 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +52 -34
- data/lib/tasks/vite.rake +17 -0
- data/lib/vite_rails.rb +5 -82
- data/lib/vite_rails/config.rb +11 -130
- data/lib/vite_rails/engine.rb +7 -11
- data/lib/vite_rails/installation.rb +52 -0
- data/lib/vite_rails/tag_helpers.rb +61 -0
- data/lib/vite_rails/version.rb +2 -2
- data/{lib/install/config/vite.json → templates/config/rails-vite.json} +1 -0
- data/{lib/install/javascript → templates}/entrypoints/application.js +0 -0
- metadata +27 -166
- data/CONTRIBUTING.md +0 -33
- data/lib/install/bin/vite +0 -17
- data/lib/install/binstubs.rb +0 -6
- data/lib/install/config/vite.config.ts +0 -11
- data/lib/install/template.rb +0 -40
- data/lib/tasks/vite/binstubs.rake +0 -12
- data/lib/tasks/vite/build.rake +0 -39
- data/lib/tasks/vite/clean.rake +0 -23
- data/lib/tasks/vite/clobber.rake +0 -20
- data/lib/tasks/vite/info.rake +0 -20
- data/lib/tasks/vite/install.rake +0 -12
- data/lib/tasks/vite/install_dependencies.rake +0 -14
- data/lib/tasks/vite/verify_install.rake +0 -23
- data/lib/vite_rails/builder.rb +0 -111
- data/lib/vite_rails/commands.rb +0 -109
- data/lib/vite_rails/dev_server.rb +0 -23
- data/lib/vite_rails/dev_server_proxy.rb +0 -57
- data/lib/vite_rails/helper.rb +0 -71
- data/lib/vite_rails/manifest.rb +0 -140
- data/lib/vite_rails/runner.rb +0 -53
- data/package.json +0 -19
- data/package/default.vite.json +0 -16
- data/test/builder_test.rb +0 -77
- data/test/commands_test.rb +0 -67
- data/test/config_test.rb +0 -133
- data/test/dev_server_proxy_test.rb +0 -102
- data/test/dev_server_test.rb +0 -9
- data/test/engine_rake_tasks_test.rb +0 -81
- data/test/helper_test.rb +0 -70
- data/test/manifest_test.rb +0 -79
- data/test/mode_test.rb +0 -16
- data/test/mounted_app/Rakefile +0 -6
- data/test/mounted_app/test/dummy/Rakefile +0 -5
- data/test/mounted_app/test/dummy/bin/rails +0 -5
- data/test/mounted_app/test/dummy/bin/rake +0 -5
- data/test/mounted_app/test/dummy/config.ru +0 -7
- data/test/mounted_app/test/dummy/config/application.rb +0 -12
- data/test/mounted_app/test/dummy/config/environment.rb +0 -5
- data/test/mounted_app/test/dummy/config/vite.json +0 -14
- data/test/mounted_app/test/dummy/package.json +0 -8
- data/test/mounted_app/test/dummy/yarn.lock +0 -208
- data/test/rake_tasks_test.rb +0 -60
- data/test/runner_test.rb +0 -31
- data/test/test_app/Rakefile +0 -5
- data/test/test_app/app/frontend/entrypoints/application.js +0 -2
- data/test/test_app/bin/vite +0 -17
- data/test/test_app/config.ru +0 -7
- data/test/test_app/config/application.rb +0 -13
- data/test/test_app/config/environment.rb +0 -6
- data/test/test_app/config/vite.json +0 -18
- data/test/test_app/config/vite_additional_paths.json +0 -5
- data/test/test_app/config/vite_public_dir.json +0 -5
- data/test/test_app/package.json +0 -13
- data/test/test_app/public/vite-production/manifest.json +0 -22
- data/test/test_app/some.config.js +0 -0
- data/test/test_app/yarn.lock +0 -11
- data/test/test_helper.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6bd0ba71782fc5f805aaa491a323dd54fa53cdb1a4eec20280dac1240ba3eaa
|
4
|
+
data.tar.gz: 732b25178ea38456fb779e132d3c9b1b3a0d51bf08c09b4bfabb99f91bbb9b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 681ab6f425a853f1f95a0ee3ef4308c56406b5e298c906f56558ff8898dcc155271de4e80dc2f4bdeb77343651ff24a58c300c4c05748a5ca9177bd0fc4f520d
|
7
|
+
data.tar.gz: c57fbf21518f89a2c7d171095802feef551422f0c6ac32b4d1a0875d4b4e41e981aac3cb72c4e2df1e7fca301fa5443b6c843eb0cf8c2469ce72720fcd41cf9a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## [2.0.3](https://github.com/ElMassimo/vite_ruby/compare/vite_rails@2.0.2...vite_rails@2.0.3) (2021-03-07)
|
2
|
+
|
3
|
+
- Add a bounded requirement to `vite_ruby` dependency.
|
4
|
+
|
5
|
+
## Vite Rails 2.0.2 (2020-02-11)
|
6
|
+
|
7
|
+
- Automatically infer `app/javascript` as the `sourceCodeDir` if it exists.
|
8
|
+
|
9
|
+
## Vite Rails 2.0.1 (2020-02-11)
|
10
|
+
|
11
|
+
- Add the CSP rules commented out when installing, in case the user hasn't uncommented them yet.
|
12
|
+
|
13
|
+
## Vite Rails 2.0.0 (2020-02-10)
|
14
|
+
|
15
|
+
- Extracted core functionality to `vite_ruby`.
|
16
|
+
- User-facing API hasn't really changed, but internal classes have been renamed.
|
17
|
+
- Installation script now injects tags to `application.html.erb` if it exists.
|
18
|
+
|
19
|
+
## Vite Rails 1.0.12 (2020-01-29)
|
20
|
+
|
21
|
+
- Add support for Vite 2.0.0-beta.56, which modified the manifest to output a `css` field in the manifest.
|
22
|
+
- Start generating an assets manifest, since 2.0.0-beta.51 stopped including non-JS entrypoints in the manifest.
|
23
|
+
|
1
24
|
## Vite Rails 1.0.11 (2020-01-24)
|
2
25
|
|
3
26
|
- Fix bug in `assetHost` that caused `base` to be configured incorrectly.
|
data/README.md
CHANGED
@@ -1,56 +1,73 @@
|
|
1
1
|
<h1 align="center">
|
2
|
-
<a href="https://vite-
|
3
|
-
<img src="https://raw.githubusercontent.com/ElMassimo/
|
2
|
+
<a href="https://vite-ruby.netlify.app/">
|
3
|
+
<img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/docs/public/logo.svg" width="120px"/>
|
4
4
|
</a>
|
5
5
|
|
6
6
|
<br>
|
7
7
|
|
8
|
-
<a href="https://vite-
|
8
|
+
<a href="https://vite-ruby.netlify.app/">
|
9
9
|
Vite Rails
|
10
10
|
</a>
|
11
11
|
|
12
12
|
<br>
|
13
|
-
|
13
|
+
|
14
14
|
<p align="center">
|
15
|
-
<a href="https://github.com/ElMassimo/
|
16
|
-
<img alt="Build Status" src="https://github.com/ElMassimo/
|
15
|
+
<a href="https://github.com/ElMassimo/vite_ruby/actions">
|
16
|
+
<img alt="Build Status" src="https://github.com/ElMassimo/vite_ruby/workflows/build/badge.svg"/>
|
17
17
|
</a>
|
18
|
-
<a href="https://codeclimate.com/github/ElMassimo/
|
19
|
-
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/
|
18
|
+
<a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
|
19
|
+
<img alt="Maintainability" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/gpa.svg"/>
|
20
20
|
</a>
|
21
|
-
<a href="https://codeclimate.com/github/ElMassimo/
|
22
|
-
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/
|
21
|
+
<a href="https://codeclimate.com/github/ElMassimo/vite_ruby">
|
22
|
+
<img alt="Test Coverage" src="https://codeclimate.com/github/ElMassimo/vite_ruby/badges/coverage.svg"/>
|
23
23
|
</a>
|
24
24
|
<a href="https://rubygems.org/gems/vite_rails">
|
25
25
|
<img alt="Gem Version" src="https://img.shields.io/gem/v/vite_rails.svg?colorB=e9573f"/>
|
26
26
|
</a>
|
27
|
-
<a href="https://github.com/ElMassimo/
|
27
|
+
<a href="https://github.com/ElMassimo/vite_ruby/blob/master/LICENSE.txt">
|
28
28
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-428F7E.svg"/>
|
29
29
|
</a>
|
30
30
|
</p>
|
31
31
|
</h1>
|
32
32
|
|
33
|
-
[website]: https://vite-
|
34
|
-
[configuration reference]: https://vite-
|
35
|
-
[features]: https://vite-
|
36
|
-
[guides]: https://vite-
|
37
|
-
[config]: https://vite-
|
38
|
-
[vite_rails]: https://github.com/ElMassimo/vite_rails
|
33
|
+
[website]: https://vite-ruby.netlify.app/
|
34
|
+
[configuration reference]: https://vite-ruby.netlify.app/config/
|
35
|
+
[features]: https://vite-ruby.netlify.app/guide/introduction.html
|
36
|
+
[guides]: https://vite-ruby.netlify.app/guide/
|
37
|
+
[config]: https://vite-ruby.netlify.app/config/
|
38
|
+
[vite_rails]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_rails
|
39
39
|
[webpacker]: https://github.com/rails/webpacker
|
40
40
|
[vite]: http://vitejs.dev/
|
41
|
-
[config file]: https://github.com/ElMassimo/
|
42
|
-
[example app]: https://github.com/ElMassimo/
|
43
|
-
[heroku]: https://vite
|
44
|
-
|
45
|
-
[
|
41
|
+
[config file]: https://github.com/ElMassimo/vite_ruby/blob/main/vite-plugin-ruby/default.vite.json
|
42
|
+
[example app]: https://github.com/ElMassimo/pingcrm-vite
|
43
|
+
[heroku]: https://pingcrm-vite.herokuapp.com/
|
44
|
+
[Issues]: https://github.com/ElMassimo/vite_ruby/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
|
45
|
+
[Discussions]: https://github.com/ElMassimo/vite_ruby/discussions
|
46
|
+
[no bundling]: https://vitejs.dev/guide/introduction.html#the-problem
|
47
|
+
[bundling]: https://vitejs.dev/guide/introduction.html#why-bundle-for-production
|
46
48
|
|
47
49
|
[Vite] is to frontend tooling as Ruby to programming, pure joy! 😍
|
48
50
|
|
49
|
-
|
51
|
+
[__Vite Rails__][vite_rails] provides a complete setup for Rails applications,
|
52
|
+
allowing you to leverage [Vite] to power the frontend of your Rails app.
|
53
|
+
|
54
|
+
## Why Vite? 🤔
|
55
|
+
|
56
|
+
Vite [does not bundle your code during development][no bundling], which means the
|
57
|
+
dev server is extremely __fast to start__, and your changes will be __updated instantly__.
|
58
|
+
|
59
|
+
In production, Vite [bundles your code][bundling]
|
60
|
+
with tree-shaking, lazy-loading, and common chunk splitting out of the box, to achieve optimal loading performance.
|
61
|
+
|
62
|
+
It also provides great defaults, and is easier to configure than similar tools like webpack.
|
63
|
+
|
64
|
+
Check [this video comparison with webpack](https://github.com/ElMassimo/jumpstart-vite)
|
65
|
+
which demonstrates the difference in boot time, or [this one](https://github.com/ElMassimo/pingcrm-vite/pull/1)
|
66
|
+
with the difference in speed during development.
|
50
67
|
|
51
68
|
## Features ⚡️
|
52
69
|
|
53
|
-
-
|
70
|
+
- 💡 Instant server start
|
54
71
|
- ⚡️ Blazing fast hot reload
|
55
72
|
- 🚀 Zero-config deployments
|
56
73
|
- 🤝 Integrated with <kbd>assets:precompile</kbd>
|
@@ -65,14 +82,14 @@ Visit the [documentation website][website] to check out the [guides] and searcha
|
|
65
82
|
Add this line to your application's Gemfile:
|
66
83
|
|
67
84
|
```ruby
|
68
|
-
gem 'vite_rails'
|
85
|
+
gem 'vite_rails' # vite_rails_legacy if using Rails 4
|
69
86
|
```
|
70
87
|
|
71
88
|
Then, run:
|
72
89
|
|
73
90
|
```bash
|
74
91
|
bundle install
|
75
|
-
|
92
|
+
bundle exec vite install
|
76
93
|
```
|
77
94
|
|
78
95
|
This will generate configuration files and a sample setup.
|
@@ -81,18 +98,19 @@ Additional installation instructions are available in the [documentation website
|
|
81
98
|
|
82
99
|
## Getting Started 💻
|
83
100
|
|
84
|
-
Restart your Rails server, and then run <kbd>bin/vite</kbd> to start the Vite development server.
|
101
|
+
Restart your Rails server, and then run <kbd>bin/vite dev</kbd> to start the Vite development server.
|
85
102
|
|
86
|
-
|
103
|
+
Visit any page and you should see a printed console output: `Vite ⚡️ Ruby`.
|
87
104
|
|
88
|
-
|
89
|
-
<%= vite_client_tag %>
|
90
|
-
<%= vite_javascript_tag 'application' %>
|
91
|
-
```
|
105
|
+
For more [guides] and a full [configuration reference], check the [documentation website][website].
|
92
106
|
|
93
|
-
|
107
|
+
## Contact ✉️
|
94
108
|
|
95
|
-
|
109
|
+
Please use [Issues] to report bugs you find, and [Discussions] to make feature requests or get help.
|
110
|
+
|
111
|
+
Don't hesitate to _⭐️ star the project_ if you find it useful!
|
112
|
+
|
113
|
+
Using it in production? Always love to hear about it! 😃
|
96
114
|
|
97
115
|
## Special Thanks 🙏
|
98
116
|
|
data/lib/tasks/vite.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vite_ruby'
|
4
|
+
ViteRuby.install_tasks
|
5
|
+
|
6
|
+
namespace :vite_rails do
|
7
|
+
desc 'Fixes Rails management of node dev dependencies (build dependencies)'
|
8
|
+
task :set_node_env do
|
9
|
+
ENV['NODE_ENV'] = 'development'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Set NODE_ENV before installation, so that Rails installs JS build dependencies
|
14
|
+
# on servers that precompile assets.
|
15
|
+
['yarn:install', 'webpacker:yarn_install'].each do |name|
|
16
|
+
Rake::Task[name].enhance([:'vite_rails:set_node_env']) if Rake::Task.task_defined?(name)
|
17
|
+
end
|
data/lib/vite_rails.rb
CHANGED
@@ -1,85 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'active_support/all'
|
3
|
+
require 'vite_ruby'
|
5
4
|
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
loader.setup
|
11
|
-
|
12
|
-
class ViteRails
|
13
|
-
# Internal: Prefix used for environment variables that modify the configuration.
|
14
|
-
ENV_PREFIX = 'VITE_RUBY'
|
15
|
-
|
16
|
-
class << self
|
17
|
-
delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, :run_proxy?, to: :instance
|
18
|
-
delegate :mode, to: :config
|
19
|
-
delegate :bootstrap, :clean, :clean_from_rake, :clobber, :build, :build_from_rake, to: :commands
|
20
|
-
|
21
|
-
attr_writer :instance
|
22
|
-
|
23
|
-
def instance
|
24
|
-
@instance ||= ViteRails.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def run(args)
|
28
|
-
$stdout.sync = true
|
29
|
-
ViteRails::Runner.new(args).run
|
30
|
-
end
|
31
|
-
|
32
|
-
# Internal: Allows to obtain any env variables for configuration options.
|
33
|
-
def load_env_variables
|
34
|
-
ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Public: Additional environment variables to pass to Vite.
|
39
|
-
#
|
40
|
-
# Example:
|
41
|
-
# ViteRails.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
|
42
|
-
cattr_accessor(:env) { load_env_variables }
|
43
|
-
|
44
|
-
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
45
|
-
|
46
|
-
# Public: Returns true if the Vite development server is running.
|
47
|
-
def dev_server_running?
|
48
|
-
run_proxy? && dev_server.running?
|
49
|
-
end
|
50
|
-
|
51
|
-
# Public: The proxy for assets should only run in development mode.
|
52
|
-
def run_proxy?
|
53
|
-
config.mode == 'development'
|
54
|
-
rescue StandardError => error
|
55
|
-
ViteRails.logger.error("Failed to check mode for Vite: #{ error.message }")
|
56
|
-
false
|
57
|
-
end
|
58
|
-
|
59
|
-
# Public: Current instance configuration for Vite.
|
60
|
-
def config
|
61
|
-
@config ||= ViteRails::Config.resolve_config
|
62
|
-
end
|
63
|
-
|
64
|
-
# Public: Keeps track of watched files and triggers builds as needed.
|
65
|
-
def builder
|
66
|
-
@builder ||= ViteRails::Builder.new(self)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Public: Allows to check if the Vite development server is running.
|
70
|
-
def dev_server
|
71
|
-
@dev_server ||= ViteRails::DevServer.new(config)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Public: Enables looking up assets managed by Vite using name and type.
|
75
|
-
def manifest
|
76
|
-
@manifest ||= ViteRails::Manifest.new(self)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Internal: Helper to run commands related with Vite.
|
80
|
-
def commands
|
81
|
-
@commands ||= ViteRails::Commands.new(self)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
ViteRails::Engine if defined?(Rails)
|
5
|
+
require 'vite_rails/version'
|
6
|
+
require 'vite_rails/config'
|
7
|
+
require 'vite_rails/tag_helpers'
|
8
|
+
require 'vite_rails/engine' if defined?(Rails)
|
data/lib/vite_rails/config.rb
CHANGED
@@ -1,134 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
def protocol
|
15
|
-
https ? 'https' : 'http'
|
16
|
-
end
|
17
|
-
|
18
|
-
def host_with_port
|
19
|
-
"#{ host }:#{ port }"
|
20
|
-
end
|
21
|
-
|
22
|
-
# Internal: Path where Vite outputs the manifest file.
|
23
|
-
def manifest_path
|
24
|
-
build_output_dir.join('manifest.json')
|
25
|
-
end
|
26
|
-
|
27
|
-
# Public: The directory where Vite will store the built assets.
|
28
|
-
def build_output_dir
|
29
|
-
root.join(public_dir, public_output_dir)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Public: The directory where the entries are located.
|
33
|
-
def resolved_entrypoints_dir
|
34
|
-
root.join(source_code_dir, entrypoints_dir)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Internal: The directory where Vite stores its processing cache.
|
38
|
-
def vite_cache_dir
|
39
|
-
root.join('node_modules/.vite')
|
40
|
-
end
|
41
|
-
|
42
|
-
# Public: Sets additional environment variables for vite-plugin-ruby.
|
43
|
-
def to_env
|
44
|
-
CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env|
|
45
|
-
unless (value = @config[option]).nil?
|
46
|
-
env["#{ ViteRails::ENV_PREFIX }_#{ option.upcase }"] = value.to_s
|
47
|
-
end
|
48
|
-
end.merge(ViteRails.env)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# Internal: Coerces all the configuration values, in case they were passed
|
54
|
-
# as environment variables which are always strings.
|
55
|
-
def coerce_values(config)
|
56
|
-
config['mode'] = config['mode'].to_s
|
57
|
-
config['port'] = config['port'].to_i
|
58
|
-
config['root'] = Pathname.new(config['root'])
|
59
|
-
config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
|
60
|
-
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https')
|
61
|
-
end
|
62
|
-
|
63
|
-
# Internal: Coerces configuration options to boolean.
|
64
|
-
def coerce_booleans(config, *names)
|
65
|
-
names.each { |name| config[name] = [true, 'true'].include?(config[name]) }
|
66
|
-
end
|
67
|
-
|
68
|
-
class << self
|
69
|
-
# Public: Returns the project configuration for Vite.
|
70
|
-
def resolve_config(**attrs)
|
71
|
-
config = attrs.transform_keys(&:to_s).reverse_merge(config_defaults)
|
72
|
-
file_path = File.join(config['root'], config['config_path'])
|
73
|
-
file_config = config_from_file(file_path, mode: config['mode'])
|
74
|
-
new DEFAULT_CONFIG.merge(file_config).merge(config_from_env).merge(config)
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
# Internal: Default values for a Rails application.
|
80
|
-
def config_defaults
|
81
|
-
{
|
82
|
-
'asset_host' => option_from_env('asset_host') || Rails.application&.config&.action_controller&.asset_host,
|
83
|
-
'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
|
84
|
-
'mode' => option_from_env('mode') || Rails.env.to_s,
|
85
|
-
'root' => option_from_env('root') || Rails.root || Dir.pwd,
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
# Internal: Used to load a JSON file from the specified path.
|
90
|
-
def load_json(path)
|
91
|
-
JSON.parse(File.read(File.expand_path(path))).deep_transform_keys(&:underscore)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Internal: Retrieves a configuration option from environment variables.
|
95
|
-
def option_from_env(name)
|
96
|
-
ViteRails.env["#{ ViteRails::ENV_PREFIX }_#{ name.upcase }"]
|
97
|
-
end
|
98
|
-
|
99
|
-
# Internal: Extracts the configuration options provided as env vars.
|
100
|
-
def config_from_env
|
101
|
-
CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env_vars|
|
102
|
-
if value = option_from_env(option)
|
103
|
-
env_vars[option] = value
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Internal: Loads the configuration options provided in a JSON file.
|
109
|
-
def config_from_file(path, mode:)
|
110
|
-
multi_env_config = load_json(path)
|
111
|
-
multi_env_config.fetch('all', {})
|
112
|
-
.merge(multi_env_config.fetch(mode, {}))
|
113
|
-
rescue Errno::ENOENT => error
|
114
|
-
warn "Check that your vite.json configuration file is available in the load path. #{ error.message }"
|
115
|
-
{}
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# Internal: Shared configuration with the Vite plugin for Ruby.
|
120
|
-
DEFAULT_CONFIG = load_json("#{ __dir__ }/../../package/default.vite.json").freeze
|
121
|
-
|
122
|
-
# Internal: Configuration options that can not be provided as env vars.
|
123
|
-
NOT_CONFIGURABLE_WITH_ENV = %w[watch_additional_paths].freeze
|
124
|
-
|
125
|
-
# Internal: Configuration options that can be provided as env vars.
|
126
|
-
CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root] - NOT_CONFIGURABLE_WITH_ENV).freeze
|
127
|
-
|
128
|
-
public
|
129
|
-
|
130
|
-
# Define getters for the configuration options.
|
131
|
-
(CONFIGURABLE_WITH_ENV + NOT_CONFIGURABLE_WITH_ENV).each do |option|
|
132
|
-
define_method(option) { @config[option] }
|
3
|
+
module ViteRails::Config
|
4
|
+
# Override: Default values for a Rails application.
|
5
|
+
def config_defaults
|
6
|
+
require 'rails'
|
7
|
+
super(
|
8
|
+
asset_host: Rails.application&.config&.action_controller&.asset_host,
|
9
|
+
mode: Rails.env.to_s,
|
10
|
+
root: Rails.root || Dir.pwd,
|
11
|
+
)
|
133
12
|
end
|
134
13
|
end
|
14
|
+
|
15
|
+
ViteRuby::Config.singleton_class.prepend(ViteRails::Config)
|
data/lib/vite_rails/engine.rb
CHANGED
@@ -4,36 +4,32 @@ require 'rails/railtie'
|
|
4
4
|
|
5
5
|
class ViteRails::Engine < Rails::Engine
|
6
6
|
initializer 'vite_rails.proxy' do |app|
|
7
|
-
app.middleware.insert_before 0,
|
7
|
+
app.middleware.insert_before 0, ViteRuby::DevServerProxy, ssl_verify_none: true if ViteRuby.run_proxy?
|
8
8
|
end
|
9
9
|
|
10
10
|
initializer 'vite_rails.helper' do
|
11
11
|
ActiveSupport.on_load(:action_controller) do
|
12
|
-
ActionController::Base.helper(ViteRails::
|
12
|
+
ActionController::Base.helper(ViteRails::TagHelpers)
|
13
13
|
end
|
14
14
|
|
15
15
|
ActiveSupport.on_load(:action_view) do
|
16
|
-
include ViteRails::
|
16
|
+
include ViteRails::TagHelpers
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
initializer 'vite_rails.logger' do
|
21
21
|
config.after_initialize do
|
22
|
-
|
23
|
-
::Rails.logger
|
24
|
-
else
|
25
|
-
ActiveSupport::TaggedLogging.new(::Rails.logger)
|
26
|
-
end
|
22
|
+
ViteRuby.instance.logger = Rails.logger
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
26
|
initializer 'vite_rails.bootstrap' do
|
31
27
|
if defined?(Rails::Server) || defined?(Rails::Console)
|
32
|
-
|
28
|
+
ViteRuby.bootstrap
|
33
29
|
if defined?(Spring)
|
34
30
|
require 'spring/watcher'
|
35
|
-
Spring.after_fork {
|
36
|
-
Spring.watch(
|
31
|
+
Spring.after_fork { ViteRuby.bootstrap }
|
32
|
+
Spring.watch(ViteRuby.config.config_path)
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|