diff --git a/Gemfile b/Gemfile index 626a9ea6..167450c7 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'dotenv-rails', '~> 2.8', '>= 2.8.1' gem 'haml', '~> 6.1', '>= 6.1.1' gem 'sass-rails', '~> 5.0', '>= 5.0.7' gem 'compass-rails', '~> 3.1' -gem 'uglifier', '~> 4.2' +gem 'terser', '~> 1.1', '>= 1.1.17' gem 'react-rails', '~> 2.7', '>= 2.7.1' gem 'jsbundling-rails', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 16c5f20c..cd9de073 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -293,13 +293,13 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) temple (0.8.2) + terser (1.1.17) + execjs (>= 0.3.0, < 3) thor (1.2.2) tilt (2.2.0) timeout (0.4.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - uglifier (4.2.0) - execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext unf_ext (0.0.8.2) @@ -348,7 +348,7 @@ DEPENDENCIES rvm-capistrano (~> 1.5.6) sanitize (~> 6.0, >= 6.0.2) sass-rails (~> 5.0, >= 5.0.7) - uglifier (~> 4.2) + terser (~> 1.1, >= 1.1.17) web-console (~> 4.2) will_paginate (~> 4.0) diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 00000000..3f6350ab --- /dev/null +++ b/bin/deploy @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Deploy a new version to production, using the Ansible playbook in `deploy/deploy.yml`. +$(dirname $0)/deploy:precompile && \ + $(dirname $0)/deploy:push diff --git a/bin/deploy:precompile b/bin/deploy:precompile new file mode 100755 index 00000000..895abfbb --- /dev/null +++ b/bin/deploy:precompile @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +# Precompile the assets for production. +RAILS_ENV=production $(dirname $0)/rails assets:precompile diff --git a/bin/deploy:push b/bin/deploy:push new file mode 100755 index 00000000..81384d5e --- /dev/null +++ b/bin/deploy:push @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Deploy a new version to production, using the Ansible playbook in `deploy/deploy.yml`. +# This skips the build step that normally runs when you just call `bin/deploy`. +ansible-playbook -i deploy/inventory.cfg deploy/deploy.yml diff --git a/bin/deploy:setup b/bin/deploy:setup new file mode 100755 index 00000000..70177f69 --- /dev/null +++ b/bin/deploy:setup @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Set up the deployment environment, using the Ansible playbook in `deploy/setup.yml`. +echo $'Setup requires you to become the root user. You\'ll need to enter the password for your account on the remote web server below, and you must be part of the `sudo` user group.' +ansible-playbook -K -i deploy/inventory.cfg deploy/setup.yml diff --git a/config/environments/development.rb b/config/environments/development.rb index c672b6ad..4ed5a6fa 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -58,6 +58,13 @@ Rails.application.configure do config.react.variant = :development + # Don't use the assets precompiled for production; recompile live instead. + # HACK: We do this by just telling it that dev assets belong in a special + # folder, so if you run precompile in development it'll look there instead, + # as recommended by the Rails guide. But I don't actually use that irl! + # https://guides.rubyonrails.org/v7.0.7/asset_pipeline.html#local-precompilation + config.assets.prefix = "/dev-assets" + # Fix file reloading in a Vagrant environment. # The `ActiveSupport::EventedFileUpdateChecker` is faster, but doesn't work # correctly for Vagrant's networked folders! diff --git a/config/environments/production.rb b/config/environments/production.rb index 04c593f5..7ca1ec18 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,7 +52,7 @@ Rails.application.configure do config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier + config.assets.js_compressor = :terser # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false diff --git a/deploy/deploy.yml b/deploy/deploy.yml index c269d653..ac5c594e 100644 --- a/deploy/deploy.yml +++ b/deploy/deploy.yml @@ -27,11 +27,14 @@ path: "{{ remote_app_root }}" state: directory + # NOTE: We skip most gitignored files, except for public/assets/*, which + # contains the assets we precompiled for production. - name: Copy local app's source files to new remote folder ansible.posix.synchronize: src: "{{ local_app_root }}/" dest: "{{ remote_app_root }}" rsync_opts: + - "--include=/public/assets/*" - "--exclude=.git" - "--filter=':- .gitignore'" diff --git a/package.json b/package.json index 80fa118c..73286ae2 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,6 @@ }, "scripts": { "build": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=/assets --loader:.js=jsx --loader:.png=file --loader:.svg=file --loader:.min.js=text", - "build:production": "yarn build --minify", - "deploy:setup": "echo $'Setup requires you to become the root user. You\\'ll need to enter the password for your account on the remote web server below, and you must be part of the `sudo` user group.' && ansible-playbook -K -i deploy/inventory.cfg deploy/setup.yml", - "deploy": "ansible-playbook -i deploy/inventory.cfg deploy/deploy.yml" + "build:production": "yarn build --minify" } } diff --git a/vendor/cache/terser-1.1.17.gem b/vendor/cache/terser-1.1.17.gem new file mode 100644 index 00000000..b3c61cf9 Binary files /dev/null and b/vendor/cache/terser-1.1.17.gem differ diff --git a/vendor/cache/uglifier-4.2.0.gem b/vendor/cache/uglifier-4.2.0.gem deleted file mode 100644 index 9b97e3c8..00000000 Binary files a/vendor/cache/uglifier-4.2.0.gem and /dev/null differ