@@ -546,121 +546,6 @@ Beware that templates use a simplified version of the logical path shown above.
546
546
For example, an ``index.html.twig `` template located in the ``templates/Default/ ``
547
547
directory of the AcmeBlogBundle, is referenced as ``@AcmeBlog/Default/index.html.twig ``.
548
548
549
- Specifics for a UX Bundle
550
- -------------------------
551
-
552
- Here are a few tricks to make your bundle install as a UX bundle.
553
-
554
- composer.json file
555
- ~~~~~~~~~~~~~~~~~~
556
-
557
- Your ``composer.json `` file must have the ``symfony-ux `` keyword:
558
-
559
- .. code-block :: json
560
-
561
- {
562
- "keywords" : [" symfony-ux" ]
563
- }
564
-
565
- Assets location
566
- ~~~~~~~~~~~~~~~
567
-
568
- Your assets must be located in one of the following directories, with a ``package.json `` file so Flex can handle it
569
- during install/update:
570
-
571
- * ``/assets `` (recommended)
572
- * ``/Resources/assets ``
573
- * ``/src/Resources/assets ``
574
-
575
- package.json file
576
- ~~~~~~~~~~~~~~~~~
577
-
578
- Your ``package.json `` file must contain a ``symfony `` config with controllers defined, and also add required packages
579
- to the ``peerDependencies ``:
580
-
581
- .. code-block :: json
582
-
583
- {
584
- "name" : " @acme/feature" ,
585
- "version" : " 1.0.0" ,
586
- "symfony" : {
587
- "controllers" : {
588
- "slug" : {
589
- "main" : " dist/controller.js" ,
590
- "webpackMode" : " eager" ,
591
- "fetch" : " eager" ,
592
- "enabled" : true ,
593
- "autoimport" : {
594
- "dist/bootstrap4-theme.css" : false ,
595
- "dist/bootstrap5-theme.css" : true
596
- }
597
- }
598
- }
599
- },
600
- "peerDependencies" : {
601
- "@hotwired/stimulus" : " ^3.0.0" ,
602
- "slugify" : " ^1.6.5"
603
- }
604
- }
605
-
606
- In this case, the file located at ``[assets directory]/dist/controller.js `` will be exposed.
607
-
608
- .. tip ::
609
-
610
- You can either write raw JS in this ``dist/controller.js `` file, or you can e.g. write your controller with
611
- TypeScript and transpile it to JavaScript.
612
-
613
- Here is an example to do so:
614
-
615
- 1. Add the following to your ``package.json `` file:
616
-
617
- .. code-block :: json
618
-
619
- {
620
- "scripts" : {
621
- "build" : " babel src --extensions .ts -d dist"
622
- },
623
- "devDependencies" : {
624
- "@babel/cli" : " ^7.20.7" ,
625
- "@babel/core" : " ^7.20.12" ,
626
- "@babel/plugin-proposal-class-properties" : " ^7.18.6" ,
627
- "@babel/preset-env" : " ^7.20.2" ,
628
- "@babel/preset-typescript" : " ^7.18.6" ,
629
- "@hotwired/stimulus" : " ^3.2.1" ,
630
- "typescript" : " ^4.9.5"
631
- }
632
- }
633
-
634
- 2. Run either ``npm install `` or ``yarn install `` to install the new dependencies.
635
-
636
- 3. Write your Stimulus controller with TypeScript in ``src/controller.ts ``.
637
-
638
- 4. Run ``npm run build `` or ``yarn run build `` to transpile your TypeScript controller into JavaScript.
639
-
640
- To use your controller in a template (e.g. one defined in your bundle) you can use it like this:
641
-
642
- .. code-block :: html+twig
643
-
644
- <div
645
- {{ stimulus_controller('acme/feature/slug', { modal: 'my-value' }) }}
646
- {#
647
- will render:
648
- data-controller="acme--feature--slug"
649
- data-acme--feature--slug-modal-value="my-value"
650
- #}
651
- >
652
- ...
653
- </div>
654
-
655
- Don't forget to add ``symfony/webpack-encore-bundle:^1.12 `` as a composer dependency to use
656
- Twig ``stimulus_* `` functions.
657
-
658
- .. tip ::
659
-
660
- Controller Naming: In this example, the ``name `` of the PHP package is ``acme/feature `` and the name
661
- of the controller in ``package.json `` is ``slug ``. So, the full controller name for Stimulus will be
662
- ``acme--feature--slug ``, though with the ``stimulus_controller() `` function, you can use ``acme/feature/slug ``.
663
-
664
549
Learn more
665
550
----------
666
551
0 commit comments