Class: Geoblacklight::Assets::ViteGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Geoblacklight::Assets::ViteGenerator
- Defined in:
- lib/generators/geoblacklight/assets/vite_generator.rb
Instance Method Summary collapse
-
#add_javascript ⇒ Object
Replace the default generated Vite entrypoint with our own.
-
#add_stylesheets ⇒ Object
Add our own stylesheets that reference the versions from npm.
-
#copy_config_vite_json ⇒ Object
Copy Vite config files.
-
#geoblacklight_base_layout ⇒ Object
Add our version of the Blacklight base layout with Vite helper tags.
-
#install_dev_dependencies ⇒ Object
The vite_rails gem doesn’t currently install the vite-plugin-rails node package, so we need to do that manually.
-
#install_vite_rails ⇒ Object
Install Vite.
-
#pin_vite_plugin_ruby ⇒ Object
The vite-plugin-ruby package has a breaking change in 5.1.2, so we need to resolve to a specific version to avoid issues.
-
#setup_npm_scripts ⇒ Object
Remove generated npm scripts from rollup and replace with our own.
-
#setup_vite ⇒ Object
Run the vite install generator (create binstubs, etc.).
Instance Method Details
#add_javascript ⇒ Object
Replace the default generated Vite entrypoint with our own
76 77 78 79 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 76 def add_javascript remove_file "app/javascript/entrypoints/application.js" copy_file "assets/application.js", "app/javascript/entrypoints/application.js" end |
#add_stylesheets ⇒ Object
Add our own stylesheets that reference the versions from npm
69 70 71 72 73 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 69 def add_stylesheets copy_file "assets/_customizations.scss", "app/javascript/stylesheets/_customizations.scss" copy_file "assets/geoblacklight.scss", "app/javascript/stylesheets/geoblacklight.scss" copy_file "assets/application.scss", "app/javascript/entrypoints/application.scss" end |
#copy_config_vite_json ⇒ Object
Copy Vite config files
35 36 37 38 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 35 def copy_config_vite_json copy_file "vite.json", "config/vite.json" copy_file "vite.config.ts", "vite.config.ts" end |
#geoblacklight_base_layout ⇒ Object
Add our version of the Blacklight base layout with Vite helper tags
30 31 32 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 30 def geoblacklight_base_layout copy_file "base.html.erb", "app/views/layouts/blacklight/base.html.erb" end |
#install_dev_dependencies ⇒ Object
The vite_rails gem doesn’t currently install the vite-plugin-rails node package, so we need to do that manually.
56 57 58 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 56 def install_dev_dependencies run "yarn add --dev vite-plugin-rails" end |
#install_vite_rails ⇒ Object
Install Vite
24 25 26 27 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 24 def install_vite_rails gem "vite_rails", "~> 3.0" run "bundle install" end |
#pin_vite_plugin_ruby ⇒ Object
The vite-plugin-ruby package has a breaking change in 5.1.2, so we need to resolve to a specific version to avoid issues. Remove after github.com/ElMassimo/vite_ruby/issues/586 is fixed.
48 49 50 51 52 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 48 def pin_vite_plugin_ruby inject_into_file "package.json", before: " \"dependencies\": {" do " \"resolutions\": { \"vite-plugin-ruby\": \"5.1.1\" },\n" end end |
#setup_npm_scripts ⇒ Object
Remove generated npm scripts from rollup and replace with our own. Adds a shortcut so that ‘yarn build’ runs our vite pipeline No easy way to do this with yarn, so we use ‘npm pkg`…
63 64 65 66 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 63 def setup_npm_scripts run "npm pkg delete scripts" run "npm pkg set scripts.build=\"vite build\"" end |
#setup_vite ⇒ Object
Run the vite install generator (create binstubs, etc.)
41 42 43 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 41 def setup_vite run "bundle exec vite install" end |