Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/manifest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ def test_lookup_success!
assert_equal lookup!("entrypoints/main", type: :typescript), lookup!("main.ts")
end

def test_custom_name_lookup_success!
entry = {
"file" => prefixed("main.CkQYLEXT.js"),
"name" => "entrypoints/custom-name",
"src" => "entrypoints/main.js",
"isEntry" => true,
}

assert_equal entry, lookup!("custom-name", type: :javascript)
end

def test_css_lookup_success!
entry = {
"isEntry" => true,
"file" => prefixed("application-ru2hYTUX.css"),
}

assert_equal entry, lookup!("stylesheets/application.css", type: :stylesheet)
end

def test_lookup_success_with_dev_server_running!
refresh_config(mode: "development")
with_dev_server_running {
Expand Down
14 changes: 14 additions & 0 deletions test/test_app/public/vite-production/.vite/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@
"assets/theme.e6d9734b.css"
]
},
"entrypoints/main.js": {
"file": "assets/main.CkQYLEXT.js",
"name": "entrypoints/custom-name",
"src": "entrypoints/main.js",
"isEntry": true
},
"stylesheets/application.scss": {
"file": "assets/application-ru2hYTUX.css",
"src": "stylesheets/application.scss",
"isEntry": true,
"names": [
"stylesheets/application.css"
]
},
"../assets/external.js": {
"file": "assets/external.d1ae13f1.js",
"src": "../assets/external.js",
Expand Down
12 changes: 11 additions & 1 deletion vite_ruby/lib/vite_ruby/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,23 @@ def vite_asset_origin

# Internal: Resolves the paths that reference a manifest entry.
def resolve_references(manifest)
asset_entries = {}
manifest.each_value do |entry|
entry["file"] = prefix_vite_asset(entry["file"])
file = entry["file"] = prefix_vite_asset(entry["file"])
%w[css assets].each do |key|
entry[key] = entry[key].map { |path| prefix_vite_asset(path) } if entry[key]
end
entry["imports"]&.map! { |name| manifest.fetch(name) }
asset_entries[entry["name"] + ".js"] = entry if entry["name"] && entry["isEntry"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding .js feels like a hack to make using vite_javascript_tag more convenient.

# handle scss/css entrypoints
entry["names"]&.each do |name|
asset_entries[name] = {
"isEntry" => true,
"file" => file,
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to point to the same entry object instead of creating a new one?

end
end
manifest.merge!(asset_entries)
end

# Internal: Resolves the manifest entry name for the specified resource.
Expand Down
Loading