Method: Proscenium::Importer.sideload

Defined in:
lib/proscenium/importer.rb

.sideload(filepath, **options) ⇒ Object

Sideloads JS and CSS assets for the given Ruby filepath.

Any files with the same base name and matching a supported extension will be sideloaded. Only one JS and one CSS file will be sideloaded, with the first match used in the following order:

- JS extensions: .tsx, .ts, .jsx, and .js.
- CSS extensions: .css.module, and .css.

Example:

- `app/views/layouts/application.rb`
- `app/views/layouts/application.css`
- `app/views/layouts/application.js`
- `app/views/layouts/application.tsx`

A request to sideload ‘app/views/layouts/application.rb` will result in `application.css` and `application.tsx` being sideloaded. `application.js` will not be sideloaded because the `.tsx` extension is matched first.

Parameters:

  • filepath (Pathname)

    Absolute file system path of the Ruby file to sideload.

  • options (Hash)

    Options to pass to ‘import`.



77
78
79
80
81
82
# File 'lib/proscenium/importer.rb', line 77

def sideload(filepath, **options)
  return if !Proscenium.config.side_load || (options[:js] == false && options[:css] == false)

  sideload_js(filepath, **options) unless options[:js] == false
  sideload_css(filepath, **options) unless options[:css] == false
end