David Kimura PRO said over 6 years ago on Stimulus Javascript Framework :

The easiest way to get started would be to download this file https://unpkg.com/stimulus/dist/stimulus.umd.js and add it to your vendor/assets/javascripts folder.

Then add the following into the app/assets/javascripts/application.js

//= require stimulus.umd

I then would create a folder in the app/assets/javascripts called stimulus.

Within this new folder, I create another application.js file with the contents

const appStimulus = Stimulus.Application.start()

Following the Copy to Clipboard example that they have on the docs, you would create a copy_to_clipboard_controller.js within the stimulus folder with the contents

appStimulus.register("copy_to_clipboard", class extends Stimulus.Controller {
  copy_text(e) {
    e.preventDefault()
    this.copy_address_field.select()
    document.execCommand("copy")
  }
  get copy_address_field() {
    return this.targets.find('copy_address_field')
  }
})

Take note that the constant that I created was appStimulus and within each controller, we first call appStimulus.register(...)

This should get you started with getting Stimulus up and running in an existing application without adding Webpack. I don't think that I would add the complexities of Webpack in a application just for Stimulus. This would be my preferred route in an existing application.

Also, you may find that there are problems deploying to production. You may need to update the Uglifier gem to a later version and change the line in your config/environments/production.rb

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = Uglifier.new(harmony: true)