@@ -23,6 +23,52 @@ The precompile hook is especially useful when you need to run commands like:
2323- ** Development** : Runs before ` bin/shakapacker --watch ` or dev server starts
2424- ** Production** : Runs before ` bundle exec rake assets:precompile `
2525
26+ ## Choosing an Approach
27+
28+ Use ` precompile_hook ` when your setup should always run preparatory commands right
29+ before Shakapacker compiles. For React on Rails projects, this is often the
30+ simplest default.
31+
32+ For projects with more custom startup needs (for example, additional build steps
33+ or strict process ordering in ` bin/dev ` ), you can run those commands explicitly
34+ before launching long-running processes instead of using ` precompile_hook ` .
35+
36+ ### Comparison
37+
38+ | Aspect | ` precompile_hook ` | Explicit setup in ` bin/dev ` |
39+ | --------| -------------------| -------------------------------|
40+ | Best for | Default/consistent pre-build tasks | Custom multi-step dev boot flows |
41+ | Runs when | Immediately before compilation starts | Wherever you place it in startup script |
42+ | Production integration | Automatic via ` assets:precompile ` | Requires explicit production wiring |
43+ | Process manager complexity | Lower | Higher (you own orchestration) |
44+ | Debugging | Centralized hook command | Fully explicit command-by-command flow |
45+
46+ ### ` shakapacker_precompile ` Interaction
47+
48+ ` shakapacker_precompile ` controls whether Shakapacker compilation is included in
49+ ` assets:precompile ` , while ` precompile_hook ` controls whether a preparatory command
50+ runs before compilation.
51+
52+ ``` yaml
53+ # Option A: Default behavior
54+ shakapacker_precompile : true
55+ precompile_hook : " bin/shakapacker-precompile-hook"
56+
57+ # Option B: You manage compilation elsewhere
58+ shakapacker_precompile : false
59+ precompile_hook : " bin/shakapacker-precompile-hook"
60+
61+ # Option C: Fully explicit startup flow (no hook)
62+ shakapacker_precompile : false
63+ # precompile_hook: not set
64+ ```
65+
66+ To temporarily skip only the hook, set:
67+
68+ ``` bash
69+ SHAKAPACKER_SKIP_PRECOMPILE_HOOK=true
70+ ```
71+
2672## Configuration
2773
2874Add the ` precompile_hook ` option to your ` config/shakapacker.yml ` :
0 commit comments