Skip to content

Document how to automatically register a stimulus controller #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tacman opened this issue May 28, 2022 · 2 comments
Closed

Document how to automatically register a stimulus controller #919

tacman opened this issue May 28, 2022 · 2 comments

Comments

@tacman
Copy link
Contributor

tacman commented May 28, 2022

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.

@tacman
Copy link
Contributor Author

tacman commented May 31, 2022

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"],

@tacman tacman closed this as completed May 31, 2022
javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Jun 10, 2022
This PR was squashed before being merged into the 6.1 branch.

Discussion
----------

Add assets to the documentation

'assets' used to be in the /Resources folder, but seems like it should be at the root now, like config and views/templates.

I'm guessing that if package.json is in right place, then flex will register the stimulus controller, although I haven't been able to do that yet: symfony/flex#919

Commits
-------

32ff705 Add assets to the documentation
@Crovitche-1623
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants