Rails 7 + esbuild + BootStrap

Database and Ruby, Python, History


创建一个新项目

rails new myblog
bundle add cssbundling-rails jsbundling-rails
./bin/rails css:install:bootstrap
./bin/rails javascript:install:esbuild

安装 Stimulus 和 Turbo Rails

yarn add @hotwired/stimulus @hotwired/turbo-rails

并且移除 Gemfile 中的 importmap,turbo-rails。

更新 app/javascript/application.js

import "@hotwired/turbo-rails";
import "./controllers";

更新 app/javascript/controllers/index.js

import { application } from "./application";

import HelloController from "./hello_controller";

application.register("hello", HelloController);

测试 js build

yarn build

删除javascript_importmap_tag

更新 app/assets/config/manifest.js

//= link_tree ../images
//= link_tree ../builds

测试 asset pipeline

bundle exec rails assets:clobber assets:precompile