Require

The Require filter supports Ruby-style require and require_relative statements by inlining the referenced files.

When this filter is active, require and require_relative statements are processed by:

  1. Reading the referenced Ruby file
  2. Converting it to JavaScript
  3. Inlining the result at the location of the require statement

This allows you to organize your Ruby source code across multiple files while producing a single bundled JavaScript output.

require function calls in expressions (e.g., fs = require("fs")) are left alone since they represent dynamic requires, not static file inclusions.

Skipping Specific Requires

You can prevent specific require or require_relative statements from being inlined by using the skip pragma:

require 'json' # Pragma: skip
require_relative 'helper'

In this example, require 'json' will be removed from the output (since json is a Ruby-only library), while require_relative 'helper' will be processed normally and its contents inlined.

This allows the Require filter to be run before the Pragma filter in the filter chain while still respecting skip directives.

See the Pragma filter documentation for more details on the skip pragma.

Next: Return