Skip to content
Merged

vite #159

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
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tmp
log
.direnv
.devcontainer
.git
.gihub
.bundle

public/assets
public/vite*
public/system

node_modules
coverage
spec
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
with:
bundler-cache: true

- uses: actions/setup-node@v5
with:
node-version: 22
- run: npm ci

- name: Setup database
run: |
bundle exec rake db:create db:schema:load
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/sanity-check-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/setup-node@v5
with:
node-version: 22
- run: npm ci

- name: Setup database
run: |
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@
._*
.idea
coverage/

# Vite Ruby
/public/vite*
node_modules

# Vite uses dotenv and suggests to ignore local-only env files. See
# https://vitejs.dev/guide/env-and-mode.html#env-files
*.local

.vite
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ RUN apt-get update -qq && apt-get install -y \
libreadline-dev \
libssl-dev \
libyaml-dev \
nodejs \
npm \
zlib1g-dev

# Copy app code and install dependencies
COPY . .

RUN npm ci
RUN bundle install --without development test

# These envs are used in the rails application. While they are entirely
Expand All @@ -62,15 +65,14 @@ RUN apt-get update -qq && apt-get install --no-install-recommends -y \
&& rm -rf /var/lib/apt/lists/*




# Set working directory
WORKDIR /app

COPY --from=assets /gems /gems
COPY --from=assets /app/public/assets /app/public/assets
COPY --from=assets /app/public/vite /app/public/vite

# Copy app code and install dependencies
# Copy app code
COPY . .

# Expose port (default Rails)
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN apt-get update -qq && apt-get install -y \
libreadline-dev \
libssl-dev \
zlib1g-dev \
# nodejs \
# yarn \
nodejs \
npm \
default-mysql-client

# Set working directory
Expand All @@ -31,7 +31,8 @@ ENV BUNDLE_PATH=/usr/local/bundle \
GEM_HOME=/usr/local/bundle
ENV PATH="$BUNDLE_BIN:$PATH"

COPY Gemfile Gemfile.lock ./
COPY Gemfile Gemfile.lock package.json package-lock.json ./
RUN npm ci
RUN bundle install

# Bring in the rest of the app (still useful for initial build cache)
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ gem "bootsnap", require: false
gem 'sprockets-rails', '~> 3.2.2'
gem 'trilogy'
gem 'uglifier'
gem 'coffee-rails'
gem "feature_flipper"

gem "vite_rails"

gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'

Expand Down
35 changes: 20 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ GEM
climate_control (0.2.0)
cocoon (1.2.15)
coderay (1.1.3)
coffee-rails (5.0.0)
coffee-script (>= 2.2.0)
railties (>= 5.2.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.3.5)
connection_pool (2.5.4)
countries (8.0.4)
Expand Down Expand Up @@ -180,6 +173,7 @@ GEM
request_store (>= 1.0)
ruby2_keywords
drb (2.2.3)
dry-cli (1.3.0)
erb (5.0.2)
erubi (1.13.1)
execjs (2.10.0)
Expand Down Expand Up @@ -256,6 +250,7 @@ GEM
msgpack (1.8.0)
multi_xml (0.7.2)
bigdecimal (~> 3.1)
mutex_m (0.3.0)
net-imap (0.4.22)
date
net-protocol
Expand Down Expand Up @@ -294,16 +289,18 @@ GEM
puma (6.6.1)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.17)
rack (3.2.1)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-session (1.0.2)
rack (< 3)
rack-proxy (0.7.7)
rack
rack-session (2.1.1)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rack-test (2.2.0)
rack (>= 1.3)
rackup (1.0.1)
rack (< 3)
webrick
rackup (2.2.1)
rack (>= 3)
rails (8.1.0.beta1)
actioncable (= 8.1.0.beta1)
actionmailbox (= 8.1.0.beta1)
Expand Down Expand Up @@ -417,9 +414,17 @@ GEM
unaccent (0.4.0)
uri (1.0.3)
useragent (0.16.11)
vite_rails (3.0.19)
railties (>= 5.1, < 9)
vite_ruby (~> 3.0, >= 3.2.2)
vite_ruby (3.9.2)
dry-cli (>= 0.7, < 2)
logger (~> 1.6)
mutex_m
rack-proxy (~> 0.6, >= 0.6.1)
zeitwerk (~> 2.2)
warden (1.2.9)
rack (>= 2.0.9)
webrick (1.9.1)
websocket (1.2.11)
websocket-driver (0.8.0)
base64
Expand Down Expand Up @@ -448,7 +453,6 @@ DEPENDENCIES
capybara (~> 3.36)
ckeditor (~> 4.3.0)
cocoon (~> 1.2.6)
coffee-rails
country_select
debug (~> 1.11)
devise (~> 4.9.4)
Expand Down Expand Up @@ -481,6 +485,7 @@ DEPENDENCIES
sprockets-rails (~> 3.2.2)
trilogy
uglifier
vite_rails
wicked
will_paginate (~> 3.1.7)

Expand Down
3 changes: 3 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

vite: bin/vite dev
web: bin/rails s
28 changes: 28 additions & 0 deletions app/frontend/entrypoints/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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'
12 changes: 12 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
<%= csrf_meta_tags %>
<meta content='width=device-width initial-scale=1 maximum-scale=1 user-scalable=no' name='viewport'>
<link rel="shortcut icon" type="image/png" href="<%= asset_path("favicon.png") %>"/>
<%= vite_client_tag %>
<%= vite_javascript_tag 'application' %>
<!--
If using a TypeScript entrypoint file:
vite_typescript_tag 'application'

If using a .jsx or .tsx entrypoint, add the extension:
vite_javascript_tag 'application.jsx'

Visit the guide for more information: https://vite-ruby.netlify.app/guide/rails
-->

</head>
<body class='<%=controller.controller_name%> <%=controller.action_name%>'>

Expand Down
110 changes: 108 additions & 2 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_requirement
@bundler_requirement ||=
env_var_version ||
cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

bundler_gem_version.approximate_recommendation
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
Loading