Assets

JavaScript

--skip-javascript [-J]

<!-- app/views/layouts/application.html.erb -->
<head>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
# bin/setup
FileUtils.chdir APP_ROOT do
# Install JavaScript dependencies
# system('bin/yarn')
end
# bin/yarn
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec 'yarnpkg', *ARGV
rescue Errno::ENOENT
$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
# config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# config/initializers/content_security_policy.rb
# Rails.application.config.content_security_policy do |policy|
# policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
# end
# Gemfile
gem 'turbolinks', '~> 5'
gem 'webpacker', '~> 4.0'
// package.json
{
"name": "my_app",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.2.2",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.10.3"
}
}

Sprockets

--skip-sprockets [-S]

# config/application.rb
require 'sprockets/railtie'
# config/environments/development.rb
class Application < Rails::Application
config.assets.debug = true
config.assets.quiet = true
end
# config/environments/production.rb
class Application < Rails::Application
config.assets.compile = false
end
# config/initializers/assets.rb
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.paths << Rails.root.join('node_modules')
# Gemfile
gem 'sass-rails', '>= 6'

Turbolinks

--skip-turbolinks

// app/javascript/packs/application.js
require('turbolinks').start()
<!-- app/views/layouts/application.html.erb -->
<head>
<%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload', media: 'all' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
# Gemfile
gem 'turbolinks', '~> 5'
// package.json
{
"dependencies": {
"turbolinks": "^5.2.0"
}
}