-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the asset pipeline with Vite in app/frontend
- Remove esbuild - Install the vite_rails gem - Move asset pipeline files into app/frontend - Run the vite installer - Replace vite-plugin-ruby with vite-plugin-rails - Move vite package from devDependencies to dependencies - Install autoprefixer - Disable autoBuild in test environment - Install modern-normalize and base stylesheets - Configure turbo/stimulus - Add InlineSvgHelper - Add a `bin/dev` script that uses run-pty - Add Safari cache workaround in development - Remove jsbundling-rails - Remove sprockets - Add Node steps to CI workflow
- Loading branch information
1 parent
c3afde2
commit d420b94
Showing
35 changed files
with
904 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { application } from "./application"; | ||
import { registerControllers } from "stimulus-vite-helpers"; | ||
|
||
const controllers = import.meta.glob("./**/*_controller.js", { eager: true }); | ||
registerControllers(application, controllers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import "~/stylesheets/index.css"; | ||
import "~/controllers"; | ||
import "@hotwired/turbo-rails"; | ||
// To see this message, add the following to the `<head>` section in your | ||
// views/layouts/application.html.erb | ||
// | ||
// <%= vite_client_tag %> | ||
// <%= vite_javascript_tag 'application' %> | ||
console.log('Vite ⚡️ Rails') | ||
|
||
// If using a TypeScript entrypoint file: | ||
// <%= vite_typescript_tag 'application' %> | ||
// | ||
// If you want to use .jsx or .tsx, add the extension: | ||
// <%= vite_javascript_tag 'application.jsx' %> | ||
|
||
console.log('Visit the guide for more information: ', 'https://vite-ruby.netlify.app/guide/rails') | ||
|
||
// Example: Load Rails libraries in Vite. | ||
// | ||
// import * as Turbo from '@hotwired/turbo' | ||
// Turbo.start() | ||
// | ||
// import ActiveStorage from '@rails/activestorage' | ||
// ActiveStorage.start() | ||
// | ||
// // Import all channels. | ||
// const channels = import.meta.globEager('./**/*_channel.js') | ||
|
||
// Example: Import a stylesheet in app/frontend/index.css | ||
// import '~/index.css' |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
This file is for base element styles, like: | ||
- Any @font-face declarations needed custom web fonts. | ||
- Default font-family on the body element. | ||
- Default foreground, background, and link colors. | ||
- Global CSS variables (declared on :root), such as color palette. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "modern-normalize"; | ||
@import "reset"; | ||
@import "base"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
:root { | ||
line-height: 1.5; | ||
-webkit-font-smoothing: antialiased; | ||
} | ||
|
||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
figure, | ||
p, | ||
ol, | ||
ul { | ||
margin: 0; | ||
} | ||
|
||
ol, | ||
ul { | ||
list-style: none; | ||
padding-inline: 0; | ||
} | ||
|
||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5 { | ||
font-size: inherit; | ||
font-weight: inherit; | ||
} | ||
|
||
img { | ||
display: block; | ||
max-inline-size: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module InlineSvgHelper | ||
def inline_svg_tag(filename, title: nil) | ||
svg = ViteInlineSvgFileLoader.named(filename) | ||
svg = svg.sub(/\A<svg/, '<svg role="img"') | ||
svg = svg.sub(/\A<svg.*?>/, safe_join(['\0', "\n", tag.title(title)])) if title.present? | ||
|
||
svg.strip.html_safe # rubocop:disable Rails/OutputSafety | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
#!/usr/bin/env sh | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
if gem list --no-installed --exact --silent foreman; then | ||
echo "Installing foreman..." | ||
gem install foreman | ||
fi | ||
|
||
# Default to port 3000 if not specified | ||
export PORT="${PORT:-3000}" | ||
|
||
exec foreman start -f Procfile.dev --env /dev/null "$@" | ||
exec "npx", "run-pty", "run-pty.json", *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'vite' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
|
||
bundle_binstub = File.expand_path("bundle", __dir__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("vite_ruby", "vite") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"all": { | ||
"sourceCodeDir": "app/frontend", | ||
"watchAdditionalPaths": [] | ||
}, | ||
"development": { | ||
"autoBuild": true, | ||
"publicOutputDir": "vite-dev", | ||
"port": 3036 | ||
}, | ||
"test": { | ||
"autoBuild": false, | ||
"publicOutputDir": "vite-test", | ||
"port": 3037 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module ViteInlineSvgFileLoader | ||
class << self | ||
def named(filename) | ||
vite = ViteRuby.instance | ||
vite_asset_path = vite.manifest.path_for(filename) | ||
|
||
if vite.dev_server_running? | ||
fetch_from_dev_server(vite_asset_path) | ||
else | ||
Rails.public_path.join(vite_asset_path.sub(%r{^/}, "")).read | ||
end | ||
end | ||
|
||
private | ||
|
||
def fetch_from_dev_server(path) | ||
config = ViteRuby.config | ||
dev_server_uri = URI("#{config.protocol}://#{config.host_with_port}#{path}") | ||
response = Net::HTTP.get_response(dev_server_uri) | ||
raise "Failed to load inline SVG from #{dev_server_uri}" unless response.is_a?(Net::HTTPSuccess) | ||
|
||
response.body | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
plugins: [require("autoprefixer")], | ||
}; |
Oops, something went wrong.