Skip to content

Commit

Permalink
Fix entrypoint issue
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Jun 11, 2024
1 parent 357f9ac commit f9dead0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning].

## [Unreleased]

### Fixed

- Fix entrypoint issue in the install generator. ([@skryukov])

## [0.3.0] - 2024-05-31

### Added
Expand Down
14 changes: 13 additions & 1 deletion lib/generators/turbo_mount/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def install_nodejs

say "Creating Turbo Mount initializer"
template "turbo-mount.js", File.join("app/javascript/turbo-mount.js")
append_to_file "app/javascript/entrypoints/application.js", %(import "./turbo-mount"\n)
begin
append_to_file js_entrypoint, %(import "./turbo-mount"\n)
rescue
say 'Could not find the application entrypoint, please add `import "./turbo-mount"` manually.', :yellow
end
warn_about_vite_plugin if vite?
end

Expand All @@ -72,6 +76,14 @@ def install_importmap
run "bin/importmap pin #{FRAMEWORKS[framework][:pins]}"
end

def js_entrypoint
if vite?
"app/javascript/entrypoints/application.js"
else
"app/javascript/application.js"
end
end

def vite?
Dir.glob(Rails.root.join("vite.config.*")).any?
end
Expand Down

0 comments on commit f9dead0

Please sign in to comment.