initial react setup

This commit is contained in:
Dylan Knutson
2023-04-02 21:34:17 +09:00
parent 4c774faafd
commit 6b4c3c2294
20 changed files with 4317 additions and 37 deletions

7
.gitignore vendored
View File

@@ -38,3 +38,10 @@
/flamegraph.svg
/app/assets/builds/*
!/app/assets/builds/.keep
/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity

View File

@@ -20,8 +20,8 @@ gem "pry-stack_explorer"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
# # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
# gem "importmap-rails"
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"
@@ -113,3 +113,6 @@ end
# gem "pg_party"
gem "tailwindcss-rails", "~> 2.0"
gem "react-rails"
gem "shakapacker"

View File

@@ -78,6 +78,10 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bindex (0.8.1)
binding_of_caller (1.0.0)
debug_inspector (>= 0.0.1)
@@ -100,6 +104,7 @@ GEM
concurrent-ruby (~> 1.2.0)
concurrent-ruby-ext (1.2.0)
concurrent-ruby (= 1.2.0)
connection_pool (2.4.0)
crass (1.0.6)
curb (1.0.5)
daemons (1.4.1)
@@ -120,6 +125,7 @@ GEM
erubi (1.12.0)
et-orbi (1.2.7)
tzinfo
execjs (2.8.1)
faiss (0.2.5)
numo-narray
rice (>= 4.0.2)
@@ -142,9 +148,6 @@ GEM
domain_name (~> 0.5)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
influxdb-client (2.9.0)
io-console (0.6.0)
irb (1.6.2)
@@ -215,6 +218,8 @@ GEM
rack (2.2.6.2)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-proxy (0.7.6)
rack
rack-test (2.0.2)
rack (>= 1.3)
rails (7.0.4.2)
@@ -248,6 +253,12 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
react-rails (2.6.2)
babel-transpiler (>= 0.7.0)
connection_pool
execjs
railties (>= 3.2)
tilt
regexp_parser (2.6.2)
reline (0.3.2)
io-console (~> 0.5)
@@ -282,6 +293,12 @@ GEM
websocket (~> 1.0)
semantic_logger (4.13.0)
concurrent-ruby (~> 1.0)
semantic_range (3.0.0)
shakapacker (6.6.0)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
@@ -297,6 +314,7 @@ GEM
tailwindcss-rails (2.0.26)
railties (>= 6.0.0)
thor (1.2.1)
tilt (2.1.0)
timeout (0.3.1)
turbo-rails (1.3.3)
actionpack (>= 6.0.0)
@@ -345,7 +363,6 @@ DEPENDENCIES
good_job
htmlbeautifier
http-cookie
importmap-rails
influxdb-client
jbuilder
kaminari
@@ -360,12 +377,14 @@ DEPENDENCIES
rails (~> 7.0.4, >= 7.0.4.2)
rails_semantic_logger
rb-bsdiff!
react-rails
ripcord
rspec-rails
ruby-prof
ruby-prof-speedscope
rufo
selenium-webdriver
shakapacker
sprockets-rails
sqlite3 (~> 1.4)
stimulus-rails

View File

@@ -1,2 +1,3 @@
web: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
shakapacker: bin/webpacker-dev-server

View File

@@ -1,3 +0,0 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import "@hotwired/turbo-rails"
import "controllers"

View File

View File

@@ -1,9 +0,0 @@
import { Application } from "@hotwired/stimulus"
const application = Application.start()
// Configure Stimulus development experience
application.debug = false
window.Stimulus = application
export { application }

View File

@@ -1,7 +0,0 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
this.element.textContent = "Hello World!"
}
}

View File

@@ -1,11 +0,0 @@
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
// Eager load all controllers defined in the import map under controllers/**/*_controller
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
// lazyLoadControllersFrom("controllers", application)

View File

@@ -0,0 +1,4 @@
// Support component names relative to this directory:
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

View File

@@ -0,0 +1,5 @@
// By default, this pack is loaded for server-side rendering.
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

View File

@@ -7,8 +7,8 @@
<%= csp_meta_tag %>
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= yield :head %>
<%= javascript_pack_tag "application" %>
</head>
<body class="h-full mx-0">
<header class="bg-slate-100 border-slate-200 border-b-2">

View File

@@ -17,6 +17,9 @@ FileUtils.chdir APP_ROOT do
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
# Install JavaScript dependencies
system!("bin/yarn")
# puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml")
# FileUtils.cp "config/database.yml.sample", "config/database.yml"

13
bin/webpacker Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "development"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
end

13
bin/webpacker-dev-server Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "development"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::DevServerRunner.run(ARGV)
end

18
bin/yarn Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
select { |dir| File.expand_path(dir) != __dir__ }.
product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]).
map { |dir, file| File.expand_path(file, dir) }.
find { |file| File.executable?(file) }
if yarn
exec yarn, *ARGV
else
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

View File

@@ -0,0 +1,5 @@
const { webpackConfig } = require('shakapacker')
// See the shakacode/shakapacker README and docs directory for advice on customizing your webpackConfig.
module.exports = webpackConfig

104
config/webpacker.yml Normal file
View File

@@ -0,0 +1,104 @@
# Note: You must restart bin/webpacker-dev-server for changes to take effect
default: &default
source_path: app/javascript
# You can have a subdirectory of the source_path, like 'packs' (recommended).
# Alternatively, you can use '/' to use the whole source_path directory.
source_entry_path: packs/
# If nested_entries is true, then we'll pick up subdirectories within the source_entry_path.
# You cannot set this option to true if you set source_entry_path to '/'
nested_entries: false
# While using a File-System-based automated bundle generation feature, miscellaneous warnings suggesting css order
# conflicts may arise due to the mini-css-extract-plugin. For projects where css ordering has been mitigated through
# consistent use of scoping or naming conventions, the css order warnings can be disabled by setting
# css_extract_ignore_order_warnings to true
css_extract_ignore_order_warnings: false
public_root_path: public
public_output_path: packs
cache_path: tmp/webpacker
webpack_compile_output: true
# See https://github.com/shakacode/shakapacker#deployment
webpacker_precompile: true
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
# manifest_path: public/packs/manifest.json
# Additional paths webpack should look up modules
# ['app/assets', 'engine/foo/app/assets']
additional_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
webpack_loader: "babel"
# Set to true to enable check for matching versions of shakapacker gem and NPM package - will raise an error if there is a mismatch or wildcard versioning is used
ensure_consistent_versioning: false
# Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
compiler_strategy: digest
development:
<<: *default
compile: true
compiler_strategy: mtime
# Reference: https://webpack.js.org/configuration/dev-server/
# Keys not described there are documented inline and in https://github.com/shakacode/shakapacker/
dev_server:
https: false
host: localhost
port: 3035
# Hot Module Replacement updates modules while the application is running without a full reload
# Used instead of the `hot` key in https://webpack.js.org/configuration/dev-server/#devserverhot
hmr: false
# If HMR is on, CSS will by inlined by delivering it as part of the script payload via style-loader. Be sure
# that you add style-loader to your project dependencies.
#
# If you want to instead deliver CSS via <link> with the mini-css-extract-plugin, set inline_css to false.
# In that case, style-loader is not needed as a dependency.
#
# mini-css-extract-plugin is a required dependency in both cases.
inline_css: true
# Defaults to the inverse of hmr. Uncomment to manually set this.
# live_reload: true
client:
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
overlay: true
# May also be a string
# webSocketURL:
# hostname: '0.0.0.0'
# pathname: '/ws'
# port: 8080
# Should we use gzip compression?
compress: true
# Note that apps that do not check the host are vulnerable to DNS rebinding attacks
allowed_hosts: "all"
# Shows progress and colorizes output of bin/webpacker[-dev-server]
pretty: true
headers:
"Access-Control-Allow-Origin": "*"
static:
watch:
ignored: "**/node_modules/**"
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true

38
package.json Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "app",
"private": true,
"dependencies": {
"@babel/core": "7",
"@babel/plugin-transform-runtime": "7",
"@babel/preset-env": "7",
"@babel/preset-react": "^7.18.6",
"@babel/runtime": "7",
"babel-loader": "8",
"compression-webpack-plugin": "9",
"css-loader": "^6.7.3",
"css-minimizer-webpack-plugin": "^5.0.0",
"mini-css-extract-plugin": "^2.7.5",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react_ujs": "^2.6.2",
"shakapacker": "6.6.0",
"style-loader": "^3.3.2",
"terser-webpack-plugin": "5",
"webpack": "5",
"webpack-assets-manifest": "5",
"webpack-cli": "4",
"webpack-dev-server": "^4.13.2",
"webpack-merge": "5"
},
"version": "0.1.0",
"babel": {
"presets": [
"./node_modules/shakapacker/package/babel/preset.js",
"@babel/preset-react"
]
},
"browserslist": [
"defaults"
]
}

4077
yarn.lock Normal file

File diff suppressed because it is too large Load Diff