Skip to content

Commit

Permalink
Update to Vite Rails 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Feb 12, 2021
1 parent 0a3c1d8 commit 25242b9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 32 deletions.
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ GEM
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
dry-cli (0.6.0)
concurrent-ruby (~> 1.0)
erubi (1.10.0)
factory_bot (6.1.0)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -231,10 +233,12 @@ GEM
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
vite_rails (1.0.12)
activesupport (>= 5.1)
rack-proxy (>= 0.6.1)
vite_rails (2.0.2)
railties (>= 5.1)
vite_ruby
vite_ruby (1.0.2)
dry-cli (~> 0.6)
rack-proxy (>= 0.6.1)
zeitwerk
warden (1.2.9)
rack (>= 2.0.9)
Expand Down
32 changes: 22 additions & 10 deletions bin/vite
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
ENV['NODE_ENV'] ||= ENV['RAILS_ENV'] == 'development' ? 'development' : 'production'
#
# 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.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

require 'bundler/setup'
bundle_binstub = File.expand_path("../bundle", __FILE__)

require 'vite_rails'

APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
ViteRails.run(ARGV)
if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /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")
4 changes: 2 additions & 2 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

if Rails.env.development?
# If you are using webpack-dev-server then specify webpack-dev-server host
policy.connect_src :self, "http://#{ ViteRails.config.host_with_port }", "ws://#{ ViteRails.config.host_with_port }"
policy.connect_src :self, "http://#{ ViteRuby.config.host_with_port }", "ws://#{ ViteRuby.config.host_with_port }"

# Inertia.js uses inline scripts to display error modal in development
policy.script_src :self, :unsafe_eval, "http://#{ ViteRails.config.host_with_port }", :unsafe_inline, 'https://polyfill.io'
policy.script_src :self, :unsafe_eval, "http://#{ ViteRuby.config.host_with_port }", :unsafe_inline, 'https://polyfill.io'
else
policy.connect_src(*[:self, ENV['MATOMO_HOST']].compact)
policy.script_src(*[:self, 'https://polyfill.io', ENV['MATOMO_HOST'], :blob].compact)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"postcss": "^8",
"postcss-nested": "^5.0.3",
"sass": "^1.32.6",
"vite": "^2.0.0-beta.65",
"vite-plugin-ruby": "^1.0.8",
"vite": "^2.0.0-beta.69",
"vite-plugin-ruby": "^1.0.11",
"vite-plugin-vue2": "^1.2.0"
},
"resolutions": {
Expand Down
33 changes: 18 additions & 15 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25242b9

Please sign in to comment.