vite_rails 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/CONTRIBUTING.md +0 -1
  4. data/lib/install/template.rb +1 -1
  5. data/lib/tasks/vite/build.rake +1 -5
  6. data/lib/tasks/vite/clean.rake +1 -3
  7. data/lib/tasks/vite/verify_install.rake +3 -3
  8. data/lib/vite_rails.rb +14 -25
  9. data/lib/vite_rails/builder.rb +11 -4
  10. data/lib/vite_rails/commands.rb +50 -10
  11. data/lib/vite_rails/config.rb +35 -23
  12. data/lib/vite_rails/dev_server_proxy.rb +27 -18
  13. data/lib/vite_rails/helper.rb +4 -2
  14. data/lib/vite_rails/manifest.rb +4 -3
  15. data/lib/vite_rails/runner.rb +2 -5
  16. data/lib/vite_rails/version.rb +1 -1
  17. data/package.json +1 -1
  18. data/test/builder_test.rb +27 -22
  19. data/test/commands_test.rb +67 -0
  20. data/test/configuration_test.rb +88 -46
  21. data/test/dev_server_proxy_test.rb +101 -0
  22. data/test/dev_server_test.rb +0 -30
  23. data/test/engine_rake_tasks_test.rb +55 -17
  24. data/test/helper_test.rb +37 -105
  25. data/test/manifest_test.rb +33 -29
  26. data/test/mode_test.rb +6 -11
  27. data/test/mounted_app/test/dummy/config/vite.json +5 -11
  28. data/test/mounted_app/test/dummy/package.json +2 -1
  29. data/test/mounted_app/test/dummy/yarn.lock +208 -0
  30. data/test/rake_tasks_test.rb +5 -19
  31. data/test/runner_test.rb +31 -0
  32. data/test/test_app/app/{javascript → frontend}/entrypoints/application.js +0 -0
  33. data/test/test_app/config/vite.json +0 -2
  34. data/test/test_app/config/vite_additional_paths.json +5 -0
  35. data/test/test_app/config/vite_public_dir.json +5 -0
  36. data/test/test_app/public/vite-production/manifest.json +22 -0
  37. data/test/test_helper.rb +48 -14
  38. metadata +21 -23
  39. data/test/command_test.rb +0 -35
  40. data/test/dev_server_runner_test.rb +0 -83
  41. data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  42. data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  43. data/test/test_app/config/vite_public_root.yml +0 -20
  44. data/test/test_app/public/vite/manifest.json +0 -36
  45. data/test/vite_runner_test.rb +0 -59
  46. data/test/webpacker_test.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01d2a1c3a1fb46873e2b8057e91829a74e6c52a010941ec8abe6ca8055242b71
4
- data.tar.gz: 8fbe4d912f70e84631a0131cfc884e4dd547f10105955d6fb1c877d69a22c03c
3
+ metadata.gz: a7036c3650b1b44c82158220474b56e26488785cefb0a99044444708d603001a
4
+ data.tar.gz: 8161dbb668ff8c2308de6783e1dbff81faf60b13cd87393348070a2f8b2f9c18
5
5
  SHA512:
6
- metadata.gz: 2807123abe076535c1b5a918d5d6d303b137e1e8025d036692162313ed479500db1fd09ba153e355e33b1a58a9072d19c17b17dc147cd09f841cceffb8d12daa
7
- data.tar.gz: 2200102393275515c8dc4ef981a9676460f27e35d48bba8c906535401aea934b5cd08fddbc19bd61bf7aaaf385c2fc7f27ca99eddca12f2ea364373fb7d2fde0
6
+ metadata.gz: a5ecb6327e2009b5fcf8aa91f90989264538db013dafc4b34a361e11b60a8d69bd394d6c6e5043583ff1cfe35fe5464424e26b616304ee30089c9e5a06fa2bda
7
+ data.tar.gz: 04124e8f3c0063b1461185fbfb665623b0c49c6ea3712952a857eb1bb00886e420ae64335609f4879377013ef7f32506ef84400af52f9a3385c90b9b5c025193
@@ -1,4 +1,8 @@
1
- ## Vite Rails 1.0.8 (2020-01-20)
1
+ ## Vite Rails 1.0.9 (2020-01-22)
2
+
3
+ - Ensure `configPath` and `publicDir` are scoped from `root`, both in Ruby and JS.
4
+
5
+ ## Vite Rails 1.0.8 (2020-01-21)
2
6
 
3
7
  - Change the default of `sourceCodeDir` to `app/frontend`, add instructions for folks migrating
4
8
  from a `app/javascript` structure.
@@ -6,7 +6,6 @@
6
6
 
7
7
  ```
8
8
  bundle install
9
- yarn
10
9
  ```
11
10
 
12
11
  ## Making sure your changes pass all tests
@@ -6,7 +6,7 @@ copy_file "#{ __dir__ }/config/vite.json", ViteRails.config.config_path
6
6
  copy_file "#{ __dir__ }/config/vite.config.ts", Rails.root.join('vite.config.ts')
7
7
 
8
8
  say 'Creating entrypoints directory'
9
- directory "#{ __dir__ }/javascript/entrypoints", ViteRails.config.source_code_dir.join(ViteRails.config.entrypoints_dir)
9
+ directory "#{ __dir__ }/javascript/entrypoints", ViteRails.config.resolved_entrypoints_dir
10
10
 
11
11
  apply "#{ __dir__ }/binstubs.rb"
12
12
 
@@ -13,11 +13,7 @@ end
13
13
  namespace :vite do
14
14
  desc 'Compile JavaScript packs using vite for production with digests'
15
15
  task build: [:'vite:verify_install', :environment] do
16
- ViteRails.with_node_env(ENV.fetch('NODE_ENV', 'production')) do
17
- ViteRails.ensure_log_goes_to_stdout do
18
- ViteRails.build || exit!
19
- end
20
- end
16
+ ViteRails.build_from_rake
21
17
  end
22
18
  end
23
19
 
@@ -5,9 +5,7 @@ $stdout.sync = true
5
5
  namespace :vite do
6
6
  desc 'Remove old compiled vites'
7
7
  task :clean, [:keep, :age] => [:'vite:verify_install', :environment] do |_, args|
8
- ViteRails.ensure_log_goes_to_stdout do
9
- ViteRails.clean(keep_up_to: Integer(args.keep || 2), age_in_seconds: Integer(args.age || 3600))
10
- end
8
+ ViteRails.clean_from_rake(args)
11
9
  end
12
10
  end
13
11
 
@@ -11,10 +11,10 @@ namespace :vite do
11
11
  WARN
12
12
  exit!
13
13
  end
14
- unless ViteRails.config.config_path.exist?
15
- path = ViteRails.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
14
+ config_path = Rails.root.join(ViteRails.config.config_path)
15
+ unless config_path.exist?
16
16
  warn <<~WARN
17
- Configuration #{ path } file for vite-plugin-ruby not found.
17
+ Configuration #{ config_path } file for vite-plugin-ruby not found.
18
18
  Make sure vite:install has run successfully before running dependent tasks.
19
19
  WARN
20
20
  exit!
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support'
4
- require 'active_support/core_ext/class/attribute_accessors'
3
+ require 'rails'
4
+ require 'active_support/all'
5
5
 
6
6
  require 'zeitwerk'
7
7
  loader = Zeitwerk::Loader.for_gem
@@ -13,18 +13,10 @@ class ViteRails
13
13
  # Internal: Prefix used for environment variables that modify the configuration.
14
14
  ENV_PREFIX = 'VITE_RUBY'
15
15
 
16
- # Public: Additional environment variables to pass to Vite.
17
- #
18
- # Example:
19
- # ViteRails.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
20
- cattr_accessor(:env) { ENV.select { |key, _| key.start_with?(ENV_PREFIX) } }
21
-
22
- cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
23
-
24
16
  class << self
25
17
  delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, to: :instance
26
18
  delegate :mode, to: :config
27
- delegate :bootstrap, :clean, :clobber, :build, to: :commands
19
+ delegate :bootstrap, :clean, :clean_from_rake, :clobber, :build, :build_from_rake, to: :commands
28
20
 
29
21
  attr_writer :instance
30
22
 
@@ -45,23 +37,20 @@ class ViteRails
45
37
  false
46
38
  end
47
39
 
48
- def with_node_env(env)
49
- original = ENV['NODE_ENV']
50
- ENV['NODE_ENV'] = env
51
- yield
52
- ensure
53
- ENV['NODE_ENV'] = original
54
- end
55
-
56
- def ensure_log_goes_to_stdout
57
- old_logger = ViteRails.logger
58
- ViteRails.logger = ActiveSupport::Logger.new(STDOUT)
59
- yield
60
- ensure
61
- ViteRails.logger = old_logger
40
+ # Internal: Allows to obtain any env variables for configuration options.
41
+ def load_env_variables
42
+ ENV.select { |key, _| key.start_with?(ENV_PREFIX) }
62
43
  end
63
44
  end
64
45
 
46
+ # Public: Additional environment variables to pass to Vite.
47
+ #
48
+ # Example:
49
+ # ViteRails.env['VITE_RUBY_CONFIG_PATH'] = 'config/alternate_vite.json'
50
+ cattr_accessor(:env) { load_env_variables }
51
+
52
+ cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
53
+
65
54
  # Public: Returns true if the Vite development server is running.
66
55
  def dev_server_running?
67
56
  ViteRails.run_proxy? && dev_server.running?
@@ -67,9 +67,18 @@ private
67
67
  def build_with_vite
68
68
  logger.info 'Building with Vite ⚡️'
69
69
 
70
- stdout, stderr, status = Open3.capture3(vite_env,
71
- "#{ which_ruby } ./bin/vite build --mode #{ config.mode }", chdir: File.expand_path(config.root))
70
+ command = "#{ which_ruby } ./bin/vite build --mode #{ config.mode }"
71
+ stdout, stderr, status = Open3.capture3(vite_env, command, chdir: File.expand_path(config.root))
72
72
 
73
+ log_build_result(stdout, stderr, status)
74
+
75
+ status.success?
76
+ end
77
+
78
+ # Internal: Outputs the build results.
79
+ #
80
+ # NOTE: By default it also outputs the manifest entries.
81
+ def log_build_result(stdout, stderr, status)
73
82
  if status.success?
74
83
  logger.info "Build with Vite complete: #{ config.build_output_dir }"
75
84
  logger.error(stderr.to_s) unless stderr.empty?
@@ -78,8 +87,6 @@ private
78
87
  non_empty_streams = [stdout, stderr].delete_if(&:empty?)
79
88
  logger.error "Build with Vite failed:\n#{ non_empty_streams.join("\n\n") }"
80
89
  end
81
-
82
- status.success?
83
90
  end
84
91
 
85
92
  # Internal: Used to prefix the bin/vite executable file.
@@ -11,6 +11,15 @@ class ViteRails::Commands
11
11
  manifest.refresh
12
12
  end
13
13
 
14
+ # Public: Defaults to production, and exits if the build fails.
15
+ def build_from_rake
16
+ with_node_env(ENV.fetch('NODE_ENV', 'production')) {
17
+ ensure_log_goes_to_stdout {
18
+ build || exit!
19
+ }
20
+ }
21
+ end
22
+
14
23
  # Public: Builds all assets that are managed by Vite, from the entrypoints.
15
24
  def build
16
25
  builder.build.tap { manifest.refresh }
@@ -22,6 +31,13 @@ class ViteRails::Commands
22
31
  config.build_cache_dir.rmtree if config.build_cache_dir.exist?
23
32
  end
24
33
 
34
+ # Public: Receives arguments from a rake task.
35
+ def clean_from_rake(args)
36
+ ensure_log_goes_to_stdout {
37
+ clean(keep_up_to: Integer(args.keep || 2), age_in_seconds: Integer(args.age || 3600))
38
+ }
39
+ end
40
+
25
41
  # Public: Cleanup old assets in the output directory.
26
42
  #
27
43
  # keep_up_to - Max amount of backups to preserve.
@@ -33,21 +49,16 @@ class ViteRails::Commands
33
49
  # To force only 1 backup to be kept: clean(1, 0)
34
50
  # To only keep files created within the last 10 minutes: clean(0, 600)
35
51
  def clean(keep_up_to: 2, age_in_seconds: 3600)
36
- return false unless config.build_output_dir.exist? && config.manifest_path.exist?
52
+ return false unless may_clean?
37
53
 
38
- versions.sort.reverse
54
+ versions
39
55
  .each_with_index
40
56
  .drop_while { |(mtime, _), index|
41
57
  max_age = [0, Time.now - Time.at(mtime)].max
42
58
  max_age < age_in_seconds || index < keep_up_to
43
59
  }
44
- .each do |(_, files), _index|
45
- files.each do |file|
46
- next unless File.file?(file)
47
-
48
- File.delete(file)
49
- logger.info("Removed #{ file }")
50
- end
60
+ .each do |(_, files), _|
61
+ clean_files(files)
51
62
  end
52
63
  true
53
64
  end
@@ -56,13 +67,42 @@ private
56
67
 
57
68
  delegate :config, :builder, :manifest, :logger, to: :@vite_rails
58
69
 
70
+ def may_clean?
71
+ config.build_output_dir.exist? && config.manifest_path.exist?
72
+ end
73
+
74
+ def clean_files(files)
75
+ files.select { |file| File.file?(file) }.each do |file|
76
+ File.delete(file)
77
+ logger.info("Removed #{ file }")
78
+ end
79
+ end
80
+
59
81
  def versions
60
82
  all_files = Dir.glob("#{ config.build_output_dir }/**/*")
61
83
  entries = all_files - [config.manifest_path] - current_version_files
62
- entries.reject { |file| File.directory?(file) }.group_by { |file| File.mtime(file).utc.to_i }
84
+ entries.reject { |file| File.directory?(file) }
85
+ .group_by { |file| File.mtime(file).utc.to_i }
86
+ .sort.reverse
63
87
  end
64
88
 
65
89
  def current_version_files
66
90
  Dir.glob(manifest.refresh.values.map { |value| config.build_output_dir.join("#{ value['file'] }*") })
67
91
  end
92
+
93
+ def with_node_env(env)
94
+ original = ENV['NODE_ENV']
95
+ ENV['NODE_ENV'] = env
96
+ yield
97
+ ensure
98
+ ENV['NODE_ENV'] = original
99
+ end
100
+
101
+ def ensure_log_goes_to_stdout
102
+ old_logger = ViteRails.logger
103
+ ViteRails.logger = ActiveSupport::Logger.new(STDOUT)
104
+ yield
105
+ ensure
106
+ ViteRails.logger = old_logger
107
+ end
68
108
  end
@@ -1,14 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  # Public: Allows to resolve configuration sourced from `config/vite.json` and
4
6
  # environment variables, combining them with the default options.
5
7
  class ViteRails::Config
6
8
  delegate :as_json, :inspect, to: :@config
7
9
 
8
- def initialize(config)
9
- @config = config.tap { coerce_values(config) }.freeze
10
+ def initialize(attrs)
11
+ @config = attrs.tap { |config| coerce_values(config) }.freeze
10
12
 
11
- config.each_key do |option|
13
+ # Define getters for the configuration options.
14
+ CONFIGURABLE_WITH_ENV.each do |option|
12
15
  define_singleton_method(option) { @config[option] }
13
16
  end
14
17
  end
@@ -31,15 +34,25 @@ class ViteRails::Config
31
34
  public_dir.join(public_output_dir)
32
35
  end
33
36
 
37
+ # Public: The directory where the entries are located.
38
+ def resolved_entrypoints_dir
39
+ source_code_dir.join(entrypoints_dir)
40
+ end
41
+
34
42
  private
35
43
 
36
44
  # Internal: Coerces all the configuration values, in case they were passed
37
45
  # as environment variables which are always strings.
38
46
  def coerce_values(config)
39
- coerce_booleans(config, 'auto_build', 'https')
40
- coerce_paths(config, 'assets_dir', 'build_cache_dir', 'config_path', 'public_dir', 'source_code_dir', 'public_output_dir', 'root')
47
+ config['mode'] = config['mode'].to_s
41
48
  config['port'] = config['port'].to_i
42
- config['root'] ||= Rails.root
49
+ coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https')
50
+ coerce_paths(config, 'config_path', 'public_output_dir', 'root')
51
+
52
+ # Prefix paths that are relative to the project root.
53
+ config.slice('build_cache_dir', 'public_dir', 'source_code_dir').each do |option, dir|
54
+ config[option] = config['root'].join(dir) if dir
55
+ end
43
56
  end
44
57
 
45
58
  # Internal: Coerces configuration options to boolean.
@@ -54,11 +67,13 @@ private
54
67
 
55
68
  class << self
56
69
  # Public: Returns the project configuration for Vite.
57
- def resolve_config
58
- new DEFAULT_CONFIG.merge(config_from_file).merge(config_from_env)
59
- rescue Errno::ENOENT => error
60
- warn "Check that your vite.json configuration file is available in the load path. #{ error.message }"
61
- new DEFAULT_CONFIG.merge(config_from_env)
70
+ def resolve_config(attrs = {})
71
+ attrs = attrs.transform_keys(&:to_s)
72
+ mode = (attrs['mode'] ||= config_option_from_env('mode') || Rails.env.to_s).to_s
73
+ root = Pathname.new(attrs['root'] ||= config_option_from_env('root') || Rails.root || Dir.pwd)
74
+ config_path = (attrs['config_path'] ||= config_option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'))
75
+ file_attrs = config_from_file(root: root, mode: mode, config_path: config_path)
76
+ new DEFAULT_CONFIG.merge(file_attrs).merge(config_from_env).merge(attrs)
62
77
  end
63
78
 
64
79
  private
@@ -70,7 +85,7 @@ private
70
85
 
71
86
  # Internal: Retrieves a configuration option from environment variables.
72
87
  def config_option_from_env(name)
73
- ENV["#{ ViteRails::ENV_PREFIX }_#{ name.upcase }"]
88
+ ViteRails.env["#{ ViteRails::ENV_PREFIX }_#{ name.upcase }"]
74
89
  end
75
90
 
76
91
  # Internal: Extracts the configuration options provided as env vars.
@@ -79,20 +94,17 @@ private
79
94
  if value = config_option_from_env(key)
80
95
  env_vars[key] = value
81
96
  end
82
- end.merge(mode: vite_mode)
83
- end
84
-
85
- # Internal: The mode Vite should run on.
86
- def vite_mode
87
- config_option_from_env('mode') || Rails.env.to_s
97
+ end
88
98
  end
89
99
 
90
100
  # Internal: Loads the configuration options provided in a JSON file.
91
- def config_from_file
92
- path = config_option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path')
93
- multi_env_config = load_json(path)
101
+ def config_from_file(root:, mode:, config_path:)
102
+ multi_env_config = load_json(root.join(config_path))
94
103
  multi_env_config.fetch('all', {})
95
- .merge(multi_env_config.fetch(vite_mode, {}))
104
+ .merge(multi_env_config.fetch(mode, {}))
105
+ rescue Errno::ENOENT => error
106
+ warn "Check that your vite.json configuration file is available in the load path. #{ error.message }"
107
+ {}
96
108
  end
97
109
  end
98
110
 
@@ -100,5 +112,5 @@ private
100
112
  DEFAULT_CONFIG = load_json("#{ __dir__ }/../../package/default.vite.json").freeze
101
113
 
102
114
  # Internal: Configuration options that can be provided as env vars.
103
- CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + ['root']).freeze
115
+ CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root]).freeze
104
116
  end
@@ -14,18 +14,8 @@ class ViteRails::DevServerProxy < Rack::Proxy
14
14
 
15
15
  # Rack: Intercept asset requests and send them to the Vite server.
16
16
  def perform_request(env)
17
- if vite_should_handle?(env['REQUEST_URI'], env['HTTP_REFERER']) && dev_server.running?
18
- env['REQUEST_URI'] = env['REQUEST_URI']
19
- .sub(vite_asset_url_prefix, '/')
20
- .sub('.ts.js', '.ts') # Patch: Rails helpers always append the extension.
21
- env['PATH_INFO'], env['QUERY_STRING'] = env['REQUEST_URI'].split('?')
22
-
23
- env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = config.host
24
- env['HTTP_X_FORWARDED_SERVER'] = config.host_with_port
25
- env['HTTP_PORT'] = env['HTTP_X_FORWARDED_PORT'] = config.port.to_s
26
- env['HTTP_X_FORWARDED_PROTO'] = env['HTTP_X_FORWARDED_SCHEME'] = config.protocol
27
- env['HTTPS'] = env['HTTP_X_FORWARDED_SSL'] = 'off' unless config.https
28
- env['SCRIPT_NAME'] = ''
17
+ if vite_should_handle?(env) && dev_server_running?
18
+ forward_to_vite_dev_server(env)
29
19
  super(env)
30
20
  else
31
21
  @app.call(env)
@@ -34,13 +24,32 @@ class ViteRails::DevServerProxy < Rack::Proxy
34
24
 
35
25
  private
36
26
 
37
- delegate :config, :dev_server, to: :@vite_rails
27
+ delegate :config, :dev_server_running?, to: :@vite_rails
38
28
 
39
- def vite_should_handle?(url, referer)
40
- return true if url.start_with?(vite_asset_url_prefix) # Vite Asset
41
- return true if url.start_with?(VITE_DEPENDENCY_PREFIX) # Vite Package Asset
42
- return true if url.include?('?t=') # Hot Reload
43
- return true if referer && URI.parse(referer).path.start_with?(vite_asset_url_prefix) # Entry Imported from another Entry.
29
+ def rewrite_uri_for_vite(env)
30
+ uri = env.fetch('REQUEST_URI') { [env['PATH_INFO'], env['QUERY_STRING']].reject(&:blank?).join('?') }
31
+ .sub(vite_asset_url_prefix, '/')
32
+ .sub('.ts.js', '.ts') # Patch: Rails helpers always append the extension.
33
+ env['PATH_INFO'], env['QUERY_STRING'] = (env['REQUEST_URI'] = uri).split('?')
34
+ end
35
+
36
+ def forward_to_vite_dev_server(env)
37
+ rewrite_uri_for_vite(env)
38
+ env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = config.host
39
+ env['HTTP_X_FORWARDED_SERVER'] = config.host_with_port
40
+ env['HTTP_PORT'] = env['HTTP_X_FORWARDED_PORT'] = config.port.to_s
41
+ env['HTTP_X_FORWARDED_PROTO'] = env['HTTP_X_FORWARDED_SCHEME'] = config.protocol
42
+ env['HTTPS'] = env['HTTP_X_FORWARDED_SSL'] = 'off' unless config.https
43
+ env['SCRIPT_NAME'] = ''
44
+ end
45
+
46
+ def vite_should_handle?(env)
47
+ path, query, referer = env['PATH_INFO'], env['QUERY_STRING'], env['HTTP_REFERER']
48
+ return true if path.start_with?(vite_asset_url_prefix) # Vite asset
49
+ return true if path.start_with?(VITE_DEPENDENCY_PREFIX) # Packages and imports
50
+ return true if query&.start_with?('t=') # Hot Reload for a stylesheet
51
+ return true if query&.start_with?('import&') # Hot Reload for an imported entrypoint
52
+ return true if referer && URI.parse(referer).path.start_with?(vite_asset_url_prefix) # Entry imported from another entry.
44
53
  end
45
54
 
46
55
  def vite_asset_url_prefix
@@ -31,7 +31,7 @@ module ViteRails::Helper
31
31
  crossorigin: 'anonymous',
32
32
  **options)
33
33
  js_entries = names.map { |name| current_vite_instance.manifest.lookup!(name, type: asset_type) }
34
- js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, type: type, crossorigin: crossorigin, **options)
34
+ js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, crossorigin: crossorigin, type: type, **options)
35
35
 
36
36
  unless skip_preload_tags || ViteRails.dev_server_running?
37
37
  preload_paths = js_entries.flat_map { |entry| entry['imports'] }.compact.uniq
@@ -39,7 +39,9 @@ module ViteRails::Helper
39
39
  end
40
40
 
41
41
  unless skip_style_tags || ViteRails.dev_server_running?
42
- style_paths = names.map { |name| current_vite_instance.manifest.lookup(name, type: :stylesheet)&.fetch('file') }.compact
42
+ style_paths = names.map { |name|
43
+ current_vite_instance.manifest.lookup(name.delete_suffix('.js'), type: :stylesheet)&.fetch('file')
44
+ }.compact
43
45
  style_tags = stylesheet_link_tag(*style_paths)
44
46
  end
45
47