You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
- add a migration checklist for moving custom build steps out of
`precompile_hook`
- clarify that `bin/dev`, Procfiles, and build commands each own
different lifecycle work
- document a script-based pattern for keeping test and production build
commands in sync without long duplicated strings
Fixes#2347
## Test plan
- `pnpm exec prettier --check
docs/oss/building-features/extensible-precompile-pattern.md`
- `pnpm start format.listDifferent`
- `script/check-docs-sidebar origin/main HEAD`
- `git diff --check`
- pre-commit hook: trailing-newlines, offline Markdown links, Prettier
- pre-push hook: branch-lint, online Markdown links
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk documentation-only change; it may influence user build
setups, but no runtime code is modified.
>
> **Overview**
> **Clarifies how to migrate from `precompile_hook` to the extensible
`bin/dev` precompile pattern** by adding a step-by-step checklist to
avoid duplicate one-time build steps across `bin/dev`, Procfiles, CI,
and production.
>
> **Expands build-command guidance** to explicitly cover both test and
production lifecycles, adds a recommended wrapper-script pattern
(`bin/build-react-on-rails`) to keep
`build_test_command`/`build_production_command` in sync (including
`node_modules_location` and cross-platform/executable-bit notes), and
updates testing docs to note that Shakapacker derives `NODE_ENV` from
`RAILS_ENV` for asset builds.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
2816101. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Documentation**
* Added a migration checklist to consolidate one-time precompile steps,
remove duplicated fragments and obsolete hooks, ensure test and
production builds include required steps, and keep long-running watchers
as separate processes.
* Expanded build-commands guidance with a reusable, mode-aware build
script pattern, explicit pre-build validation step, instructions for
making it executable, and wiring it into app startup.
[](https://app.coderabbit.ai/change-stack/shakacode/react_on_rails/pull/3226)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/oss/building-features/extensible-precompile-pattern.md
+160-3Lines changed: 160 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,34 @@ Consider this approach if you:
23
23
24
24
## Implementation
25
25
26
+
### Migration Checklist
27
+
28
+
If you have not already completed Sections 1–4 below (start at [Section 1](#1-customize-bindev)), do that first so
29
+
`bin/dev`, `config/shakapacker.yml`, your Procfiles, and your build commands are in place before you start removing
30
+
duplicates.
31
+
32
+
When moving custom build work out of `precompile_hook`, make the ownership change in one commit so the same task cannot run twice. The checklist uses letters (A–E) so the steps are easy to distinguish from the numbered Implementation sections referenced above.
33
+
34
+
A. Add (or uncomment, if already present) custom one-time tasks to the `run_precompile_tasks` method in `bin/dev`
35
+
(see [Section 1](#1-customize-bindev) for the generator-provided template).
36
+
37
+
B. Ensure `build_test_command` and `build_production_command` each include every one-time build task those lifecycles
38
+
need, such as ReScript builds, TypeScript checks or compilation, and locale generation. `bin/dev` is not invoked in
39
+
CI or production, so these commands are the only mechanism those lifecycles have.
40
+
41
+
C. After verifying the updated commands work locally, remove one-time build commands from individual Procfile process
42
+
entries. If those same commands appear as standalone steps in CI/CD pipeline scripts, remove those duplicate
43
+
invocations too. For example, remove a bare `yarn res:build` GitHub Actions step only after `build_test_command` or
44
+
`build_production_command` includes it. Do not delete entire `.github/workflows`, `.circleci/config.yml`, or Heroku
45
+
`app.json` files unless they exist solely for the migrated build step.
46
+
47
+
D. Confirm `precompile_hook` has been removed from `config/shakapacker.yml` (per
48
+
[Section 2](#2-configure-shakapackeryml)) so the same task does not also run during webpack compiles.
49
+
50
+
E. Keep long-running watchers, such as `rescript: yarn res:watch`, as separate Procfile processes.
51
+
52
+
The goal is one owner per lifecycle: `bin/dev` owns development startup, Procfile processes own long-running watchers, and React on Rails build commands own test and production compilation.
53
+
26
54
### 1. Customize bin/dev
27
55
28
56
The React on Rails generator creates a `bin/dev` script with an extensible precompile pattern. Uncomment and customize the `run_precompile_tasks` method:
Handle production builds in `config/initializers/react_on_rails.rb`:
158
+
Handle test and production builds in `config/initializers/react_on_rails.rb`. These commands must include every build step that production deploys and CI test runs require, because `bin/dev` is not part of those lifecycles:
159
+
160
+
In CI, ReactOnRails::TestHelper runs `build_test_command` when test assets need compilation. See
161
+
[testing configuration](testing-configuration.md#quick-start) for the RSpec/Minitest wiring. During
162
+
`assets:precompile`, React on Rails runs `build_production_command`.
163
+
164
+
Choose one of the following configuration styles. Use only one: Option A sets the commands directly, while Option B
165
+
points both commands at the helper script.
166
+
167
+
#### Option A - Inline commands
131
168
132
169
```ruby
133
170
ReactOnRails.configure do |config|
134
-
# Build commands should include all necessary steps
171
+
# Build commands should include all necessary steps.
172
+
# Shakapacker auto-derives NODE_ENV from RAILS_ENV, so the test command leaves NODE_ENV implicit.
173
+
# The production command sets NODE_ENV=production explicitly as a belt-and-suspenders safeguard
174
+
# against any pre-shakapacker step (e.g. a custom yarn script) that reads NODE_ENV directly.
0 commit comments