File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -604,7 +604,39 @@ to the ``peerDependencies``:
604
604
605
605
In this case, the file located at ``[assets directory]/dist/controller.js `` will be exposed.
606
606
607
- To use it in a template (e.g. one defined in your bundle) you can use it like this:
607
+ .. tip ::
608
+
609
+ You can either write raw JS in this ``dist/controller.js `` file, or you can e.g. write your controller with
610
+ TypeScript and transpile it to JavaScript.
611
+
612
+ Here is an example to do so:
613
+
614
+ 1. Add the following to your ``package.json `` file:
615
+
616
+ .. code-block :: json
617
+
618
+ {
619
+ "scripts" : {
620
+ "build" : " babel src --extensions .ts -d dist"
621
+ },
622
+ "devDependencies" : {
623
+ "@babel/cli" : " ^7.20.7" ,
624
+ "@babel/core" : " ^7.20.12" ,
625
+ "@babel/plugin-proposal-class-properties" : " ^7.18.6" ,
626
+ "@babel/preset-env" : " ^7.20.2" ,
627
+ "@babel/preset-typescript" : " ^7.18.6" ,
628
+ "@hotwired/stimulus" : " ^3.2.1"
629
+ "typescript" : " ^4.9.5"
630
+ }
631
+ }
632
+
633
+ 2. Run either ``npm install `` or ``yarn install `` to install the new dependencies.
634
+
635
+ 3. Write your Stimulus controller with TypeScript in ``src/controller.ts ``.
636
+
637
+ 4. Run ``npm run build `` or ``yarn run build `` to transpile your TypeScript controller into JavaScript.
638
+
639
+ To use your controller in a template (e.g. one defined in your bundle) you can use it like this:
608
640
609
641
.. code-block :: html+twig
610
642
You can’t perform that action at this time.
0 commit comments