Skip to content

trestle/custom.js without Sprockets #543

@nulty

Description

@nulty

I started my app with Sprockets and replaced it with Propshaft. I now have a problem adding to trestle/custom.js.

I can see there is the possibility to add javascripts through the hooks but that would require me to add the hook on every page.

I'm using javascript_bundling with esbuild.

  • I've added trestle/custom.js to excluded_paths,
    • Rails.application.config.assets.excluded_paths += %w[app/assets/javascripts/trestle/custom.js]
  • added app/assets/javascripts/custom-esm.js with my custom javascript to be included
    • import 'path/to/import`
  • I esbuild this and output it to trestle/custom.js
    • "build:js": "esbuild app/assets/javascripts/trestle/custom-esm.js --bundle --sourcemap --format=esm --outfile=app/assets/builds/trestle/custom.js --public-path=/assets"

esbuild will build my custom-esm.js and puts it in the place where Trestle expects the custom.js to be with the name custom.js.

This seems to work for me.

Great library btw, thanks for all your work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions