Skip to content

Enhancement: Add ReScript support to generator and precompile hook #2043

@justin808

Description

@justin808

Description

Currently, the shakapacker-precompile-hook generator template doesn't include ReScript build support. While the test dummy apps have ReScript integration, users who want to use ReScript with React on Rails need to manually configure their precompile hooks.

Proposed Enhancement

Add optional ReScript support to the React on Rails generator that includes:

  1. Precompile Hook Enhancement: Add ReScript build step to bin/shakapacker-precompile-hook
  2. Generator Option: Add --rescript flag to the generator (similar to --typescript)
  3. ReScript Configuration: Include proper rescript.json configuration
  4. Package.json Scripts: Add build:rescript script when ReScript is enabled
  5. Documentation: Add guide for using ReScript with React on Rails

Implementation Details

The precompile hook should:

  • Detect ReScript config files (rescript.json or bsconfig.json)
  • Validate that build:rescript script exists in package.json
  • Run ReScript build before webpack compilation
  • Provide clear error messages if build fails
  • Use subshells to avoid directory change side effects
  • Handle errors explicitly without relying on set -e

Current Workaround

Users can manually add ReScript support by modifying their bin/shakapacker-precompile-hook based on the implementation in spec/dummy/bin/shakapacker-precompile-hook.

Related

This enhancement will make React on Rails more accessible to teams using ReScript for type-safe React development.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions