Skip to content

Document how to automatically register a stimulus controller #919

Closed
@tacman

Description

@tacman
Contributor

I'd like my stimulus controller to be automatically registered in my app via an auto-recipe, like ux-chartsjs works.

Ryan has given me some guidance in SymfonyCasts stimulus controller tutorial (https://symfonycasts.com/screencast/stimulus/controllers#comment-5420791953), but in my bundle the package.json and controllers.json aren't updated by the recipe.

I'm using a Symfony 6.1 simplified recipe, so perhaps there's an issue with the condition that triggers the recipe.

Does the package.json need to be in a particular path of the bundle? I've tried it in Resources, assets, and Resources/assets

{
  "name": "@tacman/hello-bundle",
  "description": "demonstrate installation for stimulus in a bundle",
  "license": "MIT",
  "version": "1.0.0",
  "symfony": {
    "controllers": {
      "hello": {
        "main": "src/controllers/hello_controller.js",
        "webpackMode": "eager",
        "fetch": "eager",
        "enabled": true
      }
    }
  },
  "peerDependencies": {
    "@hotwired/stimulus": "^3.0.0"
  },
  "devDependencies": {
    "@hotwired/stimulus": "^3.0.0"
  },
  "dependencies": {
    "sweetalert2": "^11.4.17"
  }
}

I've enabled stimulus bridge in webpack.config.js

    // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
    .enableStimulusBridge('./assets/controllers.json')

I've put together a simple hello bundle that is structured like chartjs. This isn't working for me (not in packagist, so it requires adding the repo).

symfony new helloApp --webapp
cd helloApp && yarn install
composer config repositories.tacman_hello '{"type": "vcs", "url": "git@github.com:tacman/TacmanHelloBundle.git"}'
composer req tacman/hello-bundle:*@dev
git status

What I'm expecting is to see controllers.json add these lines;

        "@tacman/ux-hello": {
            "hello": {
                "enabled": true,
                "fetch": "eager"
            }
        }

and package.json to add this in devDependencies

       "@tacman/ux-hello": "file:vendor/tacman/hello-bundle/Resources/assets",

I imagine this is something simple, but I can't figure out what triggers this recipe. Thanks.

Activity

tacman

tacman commented on May 31, 2022

@tacman
ContributorAuthor

The answer the question of how to automatically trigger wiring the recipe is to add the keyword 'symfony-us' to the bundle's composer.json file:

{
    "name": "tacman/hello-bundle",
    "keywords": ["symfony-ux"],
added a commit that references this issue on Jun 10, 2022

minor #16829 Add assets to the documentation (tacman)

Crovitche-1623

Crovitche-1623 commented on Nov 23, 2022

@Crovitche-1623

It might be good if this necessary symfony-ux keyword could be added to the documentation for those who want to create UX bundles @javiereguiluz.

Maybe on this page: https://symfony.com/doc/current/bundles.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @tacman@Crovitche-1623

        Issue actions

          Document how to automatically register a stimulus controller · Issue #919 · symfony/flex