Skip to content
Dorian Marié edited this page Sep 23, 2021 · 3 revisions

Welcome to the jsbundling-rails wiki!

Different builds for production and development/test environments

e.g. how to have React production build on production and keep the development build on development/test environments

Create a script named bin/build with:

#!/usr/bin/env ruby

def log_and_exec(*args)
  args += ARGV
  puts args.join(" ")
  system(args.join(" "))
end

if ENV["NODE_ENV"] == "production"
  log_and_exec(
    "esbuild",
    "app/javascript/*.*",
    "--bundle",
    "--outdir=app/assets/builds",
    "'--define:process.env.NODE_ENV=\"production\"'",
    "--minify"
  )
else
  log_and_exec(
    "esbuild",
    "app/javascript/*.*",
    "--bundle",
    "--outdir=app/assets/builds",
  )
end

And then in your package.json, replace the build command with:

    "build": "./bin/build",
Clone this wiki locally