vite_rails 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +12 -1
- data/lib/install/config/vite.config.ts +1 -1
- data/lib/install/template.rb +2 -2
- data/lib/tasks/vite/build.rake +11 -1
- data/lib/tasks/vite/install_dependencies.rake +3 -9
- data/lib/vite_rails.rb +10 -10
- data/lib/vite_rails/config.rb +2 -7
- data/lib/vite_rails/helper.rb +5 -3
- data/lib/vite_rails/manifest.rb +8 -8
- data/lib/vite_rails/version.rb +1 -1
- data/package.json +5 -2
- data/test/config_test.rb +1 -1
- data/test/dev_server_proxy_test.rb +1 -0
- data/test/engine_rake_tasks_test.rb +3 -2
- data/test/helper_test.rb +1 -1
- data/test/mounted_app/test/dummy/package.json +5 -5
- data/test/mounted_app/test/dummy/yarn.lock +10 -10
- data/test/rake_tasks_test.rb +2 -2
- data/test/test_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6ae06bd2fe02d39882813646c291aa1984bf6f4bfbd337859c8527f83cdd66
|
4
|
+
data.tar.gz: 932af2eeadf8830685a6f1d30431849b1e46227147f34a11b286824d3ce80cf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67f388f8c74bd39ee14f9d8033941a7616400f9e725a1c2cec7f459f9faa06457dcb113648d9bdb672b5497093f3905bddc13928b834c91f43cef08a58de0e65
|
7
|
+
data.tar.gz: fba446503a41accc9bd4a769042858789615b2095171d6c138c0f2aaf0471ce741da98d9aa058fabc1ee92e2f667b8c19bcab48980ea4288d4b4400b53d94f15
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Vite Rails 1.0.11 (2020-01-24)
|
2
|
+
|
3
|
+
- Fix bug in `assetHost` that caused `base` to be configured incorrectly.
|
4
|
+
- Allow installing `vite` and `vite-plugin-ruby` as devDependencies, and install them when precompiling assets.
|
5
|
+
- Move `base` to the configuration root after Vite's update in beta.38
|
6
|
+
|
1
7
|
## Vite Rails 1.0.10 (2020-01-23)
|
2
8
|
|
3
9
|
- Use `path_to_asset` in `vite_asset_path` so that it's prefixed automatically
|
data/README.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
<h1 align="center">
|
2
|
-
|
2
|
+
<a href="https://vite-rails.netlify.app/">
|
3
|
+
<img src="https://raw.githubusercontent.com/ElMassimo/vite_rails/main/docs/public/logo.svg" width="120px"/>
|
4
|
+
</a>
|
5
|
+
|
6
|
+
<br>
|
7
|
+
|
8
|
+
<a href="https://vite-rails.netlify.app/">
|
9
|
+
Vite Rails
|
10
|
+
</a>
|
11
|
+
|
12
|
+
<br>
|
13
|
+
|
3
14
|
<p align="center">
|
4
15
|
<a href="https://github.com/ElMassimo/vite_rails/actions">
|
5
16
|
<img alt="Build Status" src="https://github.com/ElMassimo/vite_rails/workflows/build/badge.svg"/>
|
data/lib/install/template.rb
CHANGED
@@ -33,8 +33,8 @@ Dir.chdir(Rails.root) do
|
|
33
33
|
vite_version = package_json.match(/"vite": "(.*)"/)[1]
|
34
34
|
plugin_version = package_json.match(/"vite-plugin-ruby": "(.*)"/)[1]
|
35
35
|
|
36
|
-
say 'Installing vite as
|
37
|
-
run "yarn add vite@#{ vite_version } vite-plugin-ruby@#{ plugin_version }"
|
36
|
+
say 'Installing vite as build dependencies'
|
37
|
+
run "yarn add -D vite@#{ vite_version } vite-plugin-ruby@#{ plugin_version }"
|
38
38
|
end
|
39
39
|
|
40
40
|
say 'Vite ⚡️ Rails successfully installed! 🎉', :green
|
data/lib/tasks/vite/build.rake
CHANGED
@@ -3,14 +3,24 @@
|
|
3
3
|
$stdout.sync = true
|
4
4
|
|
5
5
|
def enhance_assets_precompile
|
6
|
+
# Before installing
|
7
|
+
['yarn:install', 'webpacker:yarn_install'].each do |name|
|
8
|
+
Rake::Task[name].enhance([:'vite:set_node_env']) if Rake::Task.task_defined?(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# After precompiling
|
6
12
|
Rake::Task['assets:precompile'].enhance do |task|
|
7
13
|
prefix = task.name.split(/#|assets:precompile/).first
|
8
|
-
|
9
14
|
Rake::Task["#{ prefix }vite:build"].invoke
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
13
18
|
namespace :vite do
|
19
|
+
desc 'Fixes Rails management of node dev dependencies (build dependencies)'
|
20
|
+
task :set_node_env do
|
21
|
+
ENV['NODE_ENV'] = 'development'
|
22
|
+
end
|
23
|
+
|
14
24
|
desc 'Compile JavaScript packs using vite for production with digests'
|
15
25
|
task build: [:'vite:verify_install', :environment] do
|
16
26
|
ViteRails.build_from_rake
|
@@ -1,19 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
namespace :vite do
|
4
|
-
desc '
|
4
|
+
desc 'Install all JavaScript dependencies as specified via Yarn'
|
5
5
|
task :install_dependencies do
|
6
6
|
valid_node_envs = %w[test development production]
|
7
7
|
node_env = ENV.fetch('NODE_ENV') { valid_node_envs.include?(Rails.env) ? Rails.env : 'production' }
|
8
8
|
Dir.chdir(Rails.root) do
|
9
|
-
|
10
|
-
|
11
|
-
"yarn install #{ v1 ? '--no-progress --frozen-lockfile' : '--immutable' }"
|
12
|
-
elsif Rails.root.join('pnpm-lock.yaml').exist?
|
13
|
-
'pnpm install'
|
14
|
-
else
|
15
|
-
'npm ci'
|
16
|
-
end
|
9
|
+
v1 = `yarn --version`.start_with?('1')
|
10
|
+
install_command = "yarn install #{ v1 ? '--no-progress --frozen-lockfile' : '--immutable' } --production=false"
|
17
11
|
system({ 'NODE_ENV' => node_env }, install_command)
|
18
12
|
end
|
19
13
|
end
|
data/lib/vite_rails.rb
CHANGED
@@ -14,7 +14,7 @@ class ViteRails
|
|
14
14
|
ENV_PREFIX = 'VITE_RUBY'
|
15
15
|
|
16
16
|
class << self
|
17
|
-
delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, to: :instance
|
17
|
+
delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, :run_proxy?, to: :instance
|
18
18
|
delegate :mode, to: :config
|
19
19
|
delegate :bootstrap, :clean, :clean_from_rake, :clobber, :build, :build_from_rake, to: :commands
|
20
20
|
|
@@ -29,14 +29,6 @@ class ViteRails
|
|
29
29
|
ViteRails::Runner.new(args).run
|
30
30
|
end
|
31
31
|
|
32
|
-
# Public: The proxy for assets should only run in development mode.
|
33
|
-
def run_proxy?
|
34
|
-
config.mode == 'development'
|
35
|
-
rescue StandardError => error
|
36
|
-
logger.error("Failed to check mode for Vite: #{ error.message }")
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
32
|
# Internal: Allows to obtain any env variables for configuration options.
|
41
33
|
def load_env_variables
|
42
34
|
ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
|
@@ -53,7 +45,15 @@ class ViteRails
|
|
53
45
|
|
54
46
|
# Public: Returns true if the Vite development server is running.
|
55
47
|
def dev_server_running?
|
56
|
-
|
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
57
|
end
|
58
58
|
|
59
59
|
# Public: Current instance configuration for Vite.
|
data/lib/vite_rails/config.rb
CHANGED
@@ -55,7 +55,7 @@ private
|
|
55
55
|
def coerce_values(config)
|
56
56
|
config['mode'] = config['mode'].to_s
|
57
57
|
config['port'] = config['port'].to_i
|
58
|
-
|
58
|
+
config['root'] = Pathname.new(config['root'])
|
59
59
|
config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
|
60
60
|
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https')
|
61
61
|
end
|
@@ -65,14 +65,9 @@ private
|
|
65
65
|
names.each { |name| config[name] = [true, 'true'].include?(config[name]) }
|
66
66
|
end
|
67
67
|
|
68
|
-
# Internal: Converts configuration options to pathname.
|
69
|
-
def coerce_paths(config, *names)
|
70
|
-
names.each { |name| config[name] = Pathname.new(config[name]) unless config[name].nil? }
|
71
|
-
end
|
72
|
-
|
73
68
|
class << self
|
74
69
|
# Public: Returns the project configuration for Vite.
|
75
|
-
def resolve_config(attrs
|
70
|
+
def resolve_config(**attrs)
|
76
71
|
config = attrs.transform_keys(&:to_s).reverse_merge(config_defaults)
|
77
72
|
file_path = File.join(config['root'], config['config_path'])
|
78
73
|
file_config = config_from_file(file_path, mode: config['mode'])
|
data/lib/vite_rails/helper.rb
CHANGED
@@ -11,7 +11,9 @@ module ViteRails::Helper
|
|
11
11
|
|
12
12
|
# Public: Renders a script tag for vite/client to enable HMR in development.
|
13
13
|
def vite_client_tag
|
14
|
-
|
14
|
+
return unless current_vite_instance.dev_server_running?
|
15
|
+
|
16
|
+
content_tag('script', '', src: current_vite_instance.manifest.prefix_vite_asset('@vite/client'), type: 'module')
|
15
17
|
end
|
16
18
|
|
17
19
|
# Public: Resolves the path for the specified Vite asset.
|
@@ -33,12 +35,12 @@ module ViteRails::Helper
|
|
33
35
|
js_entries = names.map { |name| current_vite_instance.manifest.lookup!(name, type: asset_type) }
|
34
36
|
js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, crossorigin: crossorigin, type: type, **options)
|
35
37
|
|
36
|
-
unless skip_preload_tags ||
|
38
|
+
unless skip_preload_tags || current_vite_instance.dev_server_running?
|
37
39
|
preload_paths = js_entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
38
40
|
preload_tags = preload_paths.map { |path| preload_link_tag(path, crossorigin: crossorigin) }
|
39
41
|
end
|
40
42
|
|
41
|
-
unless skip_style_tags ||
|
43
|
+
unless skip_style_tags || current_vite_instance.dev_server_running?
|
42
44
|
style_paths = names.map { |name|
|
43
45
|
current_vite_instance.manifest.lookup(name.delete_suffix('.js'), type: :stylesheet)&.fetch('file')
|
44
46
|
}.compact
|
data/lib/vite_rails/manifest.rb
CHANGED
@@ -42,6 +42,11 @@ class ViteRails::Manifest
|
|
42
42
|
@manifest = load_manifest
|
43
43
|
end
|
44
44
|
|
45
|
+
# Public: Scopes an asset to the output folder in public, as a path.
|
46
|
+
def prefix_vite_asset(path)
|
47
|
+
File.join("/#{ config.public_output_dir }", path)
|
48
|
+
end
|
49
|
+
|
45
50
|
private
|
46
51
|
|
47
52
|
delegate :config, :builder, :dev_server_running?, to: :@vite_rails
|
@@ -55,7 +60,7 @@ private
|
|
55
60
|
# Internal: Finds the specified entry in the manifest.
|
56
61
|
def find_manifest_entry(name)
|
57
62
|
if dev_server_running?
|
58
|
-
{ 'file' =>
|
63
|
+
{ 'file' => prefix_vite_asset(name.to_s) }
|
59
64
|
else
|
60
65
|
manifest[name.to_s]
|
61
66
|
end
|
@@ -80,8 +85,8 @@ private
|
|
80
85
|
def load_manifest
|
81
86
|
if config.manifest_path.exist?
|
82
87
|
JSON.parse(config.manifest_path.read).each do |_, entry|
|
83
|
-
entry['file'] =
|
84
|
-
entry['imports'] = entry['imports']&.map { |path|
|
88
|
+
entry['file'] = prefix_vite_asset(entry['file'])
|
89
|
+
entry['imports'] = entry['imports']&.map { |path| prefix_vite_asset(path) }
|
85
90
|
end
|
86
91
|
else
|
87
92
|
{}
|
@@ -96,11 +101,6 @@ private
|
|
96
101
|
extension ? "#{ name }.#{ extension }" : name
|
97
102
|
end
|
98
103
|
|
99
|
-
# Internal: Scopes the paths in the manifest to the output folder in public.
|
100
|
-
def within_public_output_dir(path)
|
101
|
-
"/#{ config.public_output_dir.join(path) }"
|
102
|
-
end
|
103
|
-
|
104
104
|
# Internal: Allows to receive :javascript and :stylesheet as :type in helpers.
|
105
105
|
def extension_for_type(entry_type)
|
106
106
|
case entry_type
|
data/lib/vite_rails/version.rb
CHANGED
data/package.json
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "only-for-workflows",
|
3
3
|
"version": "unknown",
|
4
|
+
"license": "MIT",
|
4
5
|
"scripts": {
|
5
6
|
"docs": "npm -C docs run docs",
|
6
7
|
"docs:build": "npm -C docs run docs:build",
|
7
8
|
"docs:search": "npm -C docs run docs:search",
|
8
9
|
"docs:lint": "npm -C docs run lint",
|
10
|
+
"build": "rm -rf package/dist && npm -C package run prerelease",
|
11
|
+
"release": "rm -rf package/dist && npm -C package run release",
|
9
12
|
"lint": "npm -C package run lint",
|
10
13
|
"test": "npm -C package run test"
|
11
14
|
},
|
12
15
|
"dependencies": {
|
13
|
-
"vite": "^2.0.0-beta.
|
14
|
-
"vite-plugin-ruby": "^1.0.
|
16
|
+
"vite": "^2.0.0-beta.46",
|
17
|
+
"vite-plugin-ruby": "^1.0.5"
|
15
18
|
}
|
16
19
|
}
|
data/test/config_test.rb
CHANGED
@@ -120,7 +120,7 @@ class ConfigTest < ViteRails::Test
|
|
120
120
|
assert_equal 'config/vite_additional_paths.json', @config.config_path
|
121
121
|
assert_pathname 'tmp/vitebuild', @config.build_cache_dir
|
122
122
|
assert_equal 'pb', @config.public_dir
|
123
|
-
assert_equal
|
123
|
+
assert_equal 'ft', @config.public_output_dir
|
124
124
|
assert_pathname 'pb/ft', @config.build_output_dir
|
125
125
|
assert_equal 'as', @config.assets_dir
|
126
126
|
assert_equal 'app', @config.source_code_dir
|
@@ -11,6 +11,7 @@ class DevServerProxyTest < ViteRails::Test
|
|
11
11
|
[200, { 'Content-Type' => 'application/json' }, env.to_json]
|
12
12
|
})
|
13
13
|
# Avoid actually using the proxy.
|
14
|
+
Rack::Proxy.remove_method(:perform_request)
|
14
15
|
Rack::Proxy.define_method(:perform_request) { |env| capture_app.call(env) }
|
15
16
|
|
16
17
|
ViteRails::DevServerProxy.new(capture_app)
|
@@ -38,13 +38,13 @@ class EngineRakeTasksTest < Minitest::Test
|
|
38
38
|
within_mounted_app { `bundle exec rake app:vite:clobber` }
|
39
39
|
refute app_public_dir.exist?
|
40
40
|
rescue Minitest::Assertion => error
|
41
|
-
raise error
|
41
|
+
raise error, [error.message, @command_results.join("\n\n")].join("\n")
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def within_mounted_app
|
47
|
-
Dir.chdir(mounted_app_path) { yield }
|
47
|
+
Dir.chdir(mounted_app_path) { yield }.tap { |result| @command_results << result }
|
48
48
|
end
|
49
49
|
|
50
50
|
def mounted_app_path
|
@@ -76,5 +76,6 @@ private
|
|
76
76
|
vite_config_ts_path.delete if vite_config_ts_path.exist?
|
77
77
|
app_frontend_dir.rmtree if app_frontend_dir.exist?
|
78
78
|
app_public_dir.rmtree if app_public_dir.exist?
|
79
|
+
@command_results = []
|
79
80
|
end
|
80
81
|
end
|
data/test/helper_test.rb
CHANGED
@@ -22,7 +22,7 @@ class HelperTest < ActionView::TestCase
|
|
22
22
|
def test_vite_client_tag
|
23
23
|
assert_nil vite_client_tag
|
24
24
|
with_dev_server_running {
|
25
|
-
assert_equal '<script src="/@vite/client" type="module"></script>', vite_client_tag
|
25
|
+
assert_equal '<script src="/vite-production/@vite/client" type="module"></script>', vite_client_tag
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
@@ -35,7 +35,7 @@ colorette@^1.2.1:
|
|
35
35
|
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
|
36
36
|
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
|
37
37
|
|
38
|
-
esbuild@^0.8.
|
38
|
+
esbuild@^0.8.34:
|
39
39
|
version "0.8.34"
|
40
40
|
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6"
|
41
41
|
integrity sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ==
|
@@ -188,19 +188,19 @@ to-regex-range@^5.0.1:
|
|
188
188
|
dependencies:
|
189
189
|
is-number "^7.0.0"
|
190
190
|
|
191
|
-
vite-plugin-ruby@^1.0.
|
192
|
-
version "1.0.
|
193
|
-
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-1.0.
|
194
|
-
integrity sha512-
|
191
|
+
vite-plugin-ruby@^1.0.4:
|
192
|
+
version "1.0.4"
|
193
|
+
resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-1.0.4.tgz#0f4a263fd79a082a84917a54b0881f02a3bbfa61"
|
194
|
+
integrity sha512-WJE+c2TGLwcbSHzkqcwCmPcHxasUnXmx5Bi1HPO89Yo+Mggi8t/fO/WIPUF7NxSlp9q2lq5/L3Vnkt3R/tolPg==
|
195
195
|
dependencies:
|
196
196
|
fast-glob "^3.2.4"
|
197
197
|
|
198
|
-
vite@^2.0.0-beta.
|
199
|
-
version "2.0.0-beta.
|
200
|
-
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.
|
201
|
-
integrity sha512
|
198
|
+
vite@^2.0.0-beta.46:
|
199
|
+
version "2.0.0-beta.46"
|
200
|
+
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.46.tgz#9c0d35019c350fbebd17f84c4e7243fffccd1819"
|
201
|
+
integrity sha512-RiiJdjiFDaM9youfcTFnCztstwBXHHSdsSATZVD5A4QSb39KJRTpSKoveFo0PT7VJM5HjOP7QC/sVOqX011F6Q==
|
202
202
|
dependencies:
|
203
|
-
esbuild "^0.8.
|
203
|
+
esbuild "^0.8.34"
|
204
204
|
postcss "^8.2.1"
|
205
205
|
resolve "^1.19.0"
|
206
206
|
rollup "^2.35.1"
|
data/test/rake_tasks_test.rb
CHANGED
@@ -38,8 +38,8 @@ class RakeTasksTest < Minitest::Test
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
'Expected
|
41
|
+
assert_includes installed_node_module_names, 'right-pad',
|
42
|
+
'Expected development dependencies to be installed as well'
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
data/test/test_helper.rb
CHANGED
@@ -53,7 +53,7 @@ private
|
|
53
53
|
klass = ViteRails::Runner
|
54
54
|
instance = klass.new(argv)
|
55
55
|
mock = Minitest::Mock.new
|
56
|
-
mock.expect(:call, nil, [ViteRails.
|
56
|
+
mock.expect(:call, nil, [ViteRails.config.to_env, *command, *argv, *flags])
|
57
57
|
|
58
58
|
klass.stub(:new, instance) do
|
59
59
|
instance.stub(:executable_exists?, !use_yarn) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -185,8 +185,8 @@ homepage: https://github.com/ElMassimo/vite_rails
|
|
185
185
|
licenses:
|
186
186
|
- MIT
|
187
187
|
metadata:
|
188
|
-
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.
|
189
|
-
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.
|
188
|
+
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.11
|
189
|
+
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.11/CHANGELOG.md
|
190
190
|
post_install_message:
|
191
191
|
rdoc_options: []
|
192
192
|
require_paths:
|