Skip to content

Commit

Permalink
Updating the system from webpacker to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole committed Sep 8, 2022
1 parent 68d75dd commit 3124cdf
Show file tree
Hide file tree
Showing 25 changed files with 599 additions and 10,208 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ yarn-debug.log*
.DS_Store

/spec/fixtures/storage/

# 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

1 change: 1 addition & 0 deletions Capfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ install_plugin Capistrano::SCM::Git
# require "capistrano/bundler"
# require "capistrano/rails/assets"
# require "capistrano/rails/migrations"
require "capistrano/rails"
require "capistrano/passenger"
require "whenever/capistrano"

Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ gem "pg"
gem "puma", "~> 5.0"
# Use SCSS for stylesheets
gem "sass-rails", ">= 6"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem "webpacker", "~> 5.0"
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem "turbolinks", "~> 5"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
Expand All @@ -29,6 +27,7 @@ gem "jbuilder", "~> 2.7"
gem "nokogiri", ">= 1.13.4"
gem "rolify"
gem "rspec-rails", "~> 5.0.0"
gem "vite_rails"
gem "webmock"
gem "whenever"

Expand Down
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
docile (1.4.0)
dry-cli (0.7.0)
dry-core (0.8.1)
concurrent-ruby (~> 1.0)
dry-monads (1.4.0)
Expand Down Expand Up @@ -373,7 +374,6 @@ GEM
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -415,6 +415,13 @@ GEM
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
vite_rails (3.0.12)
railties (>= 5.1, < 8)
vite_ruby (~> 3.0, >= 3.2.2)
vite_ruby (3.2.3)
dry-cli (~> 0.7.0)
rack-proxy (~> 0.6, >= 0.6.1)
zeitwerk (~> 2.2)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.0)
Expand All @@ -430,11 +437,6 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webpacker (5.4.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -499,10 +501,10 @@ DEPENDENCIES
spring
turbolinks (~> 5)
tzinfo-data
vite_rails
web-console (>= 4.1.0)
webdrivers
webmock
webpacker (~> 5.0)
whenever

BUNDLED WITH
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
12 changes: 6 additions & 6 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
*
*/

@import "variables/typography";
@import "components/container";
@import "components/header";
@import "components/footer";
@import "components/works";
@import "components/works/form";
@import "variables/typography.scss";
@import "components/container.scss";
@import "components/header.scss";
@import "components/footer.scss";
@import "components/works.scss";
@import "components/works/form.scss";

.hidden {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_container.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "./variables/typography";
@import "./variables/typography.scss";

.container,
.container-lg,
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/footer.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "./variables/typography";
@import "./variables/typography.scss";

#footer {
font-family: "Open Sans", sans-serif;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/header.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "./variables/typography";
@import "./variables/typography.scss";

header {
font-family: "Open Sans", sans-serif;
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/channels/index.js

This file was deleted.

46 changes: 46 additions & 0 deletions app/javascript/entrypoints/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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('../channels/*.js')

// Example: Import a stylesheet in app/frontend/index.css
// import '~/index.css'

import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
// Provides @mention functionality in textboxes (adds to jQuery UI autocomplete)
import "./vendor/jquery-ui-triggeredAutocomplete"
import WorkForm from "./works/form"

Turbolinks.start()
ActiveStorage.start()

$(document).ready( (event) => {

$(".work-form").each( (index, element) => {
const $element = $(element);
const work = $element.data('work');
const workForm = new WorkForm($element, work);
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 0 additions & 25 deletions app/javascript/packs/application.js

This file was deleted.

18 changes: 15 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<%= favicon_link_tag 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>
Expand All @@ -39,7 +51,7 @@

<!-- Provides @mention functionality in textboxes (adds to jQuery UI autocomplete)-->

<%= javascript_pack_tag 'file_upload', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'orcid', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= vite_javascript_tag 'file_upload', 'data-turbolinks-track': 'reload' %>
<%= vite_javascript_tag 'orcid', 'data-turbolinks-track': 'reload' %>
<%= vite_javascript_tag 'application', 'data-turbolinks-track': 'reload' %>
<% end %>
29 changes: 29 additions & 0 deletions bin/vite
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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.
#

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

bundle_binstub = File.expand_path("../bundle", __FILE__)

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")
2 changes: 2 additions & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# Workaround for this issue: https://github.com/capistrano/rails/issues/235
Rake::Task["deploy:assets:backup_manifest"].clear_actions

set :assets_prefix, "describe/assets/"
2 changes: 1 addition & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass

config.assets.prefix = "/describe/assets/"
config.assets.prefix = "vite-staging"

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
Expand Down
12 changes: 12 additions & 0 deletions config/initializers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@
# policy.img_src :self, :https, :data
# policy.object_src :none
# policy.script_src :self, :https
# Allow @vite/client to hot reload javascript changes in development
# policy.script_src *policy.script_src, :unsafe_eval, "http://#{ ViteRuby.config.host_with_port }" if Rails.env.development?

# You may need to enable this in production as well depending on your setup.
# policy.script_src *policy.script_src, :blob if Rails.env.test?

# policy.style_src :self, :https
# Allow @vite/client to hot reload style changes in development
# policy.style_src *policy.style_src, :unsafe_inline if Rails.env.development?

# # If you are using webpack-dev-server then specify webpack-dev-server host
# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
# Allow @vite/client to hot reload changes in development
# policy.connect_src *policy.connect_src, "ws://#{ ViteRuby.config.host_with_port }" if Rails.env.development?


# # Specify URI for violation reports
# # policy.report_uri "/csp-violation-report-endpoint"
Expand Down
20 changes: 20 additions & 0 deletions config/vite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"all": {
"sourceCodeDir": "app/javascript",
"watchAdditionalPaths": []
},
"staging": {
"publicOutputDir": "vite-staging",
"port": 3036
},
"development": {
"autoBuild": true,
"publicOutputDir": "vite-dev",
"port": 3036
},
"test": {
"autoBuild": true,
"publicOutputDir": "vite-test",
"port": 3037
}
}
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "^5.4.3",
"ejs": "^3.1.7",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"@webpack-cli/serve": "0.2.0",
"command-line-args": "^5.2.1",
"webpack-dev-server": "^3.9.0"
"vite": "^3.0.0",
"vite-plugin-ruby": "^3.1.0"
}
}
8 changes: 8 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vite'
import RubyPlugin from 'vite-plugin-ruby'

export default defineConfig({
plugins: [
RubyPlugin(),
],
})
Loading

0 comments on commit 3124cdf

Please sign in to comment.