From 58d8c827e0835ea38fbb242349c132e81897edc8 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 2 Oct 2022 22:09:01 +0200 Subject: [PATCH] Install and setup Stimulus --- app/javascript/packs/application.ts | 9 ++++++++- babel.config.js | 2 +- package.json | 2 ++ yarn.lock | 10 ++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index 7b6b73c1..82068a43 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -1,5 +1,8 @@ require('../styles/application.scss'); +import { Application } from '@hotwired/stimulus'; +import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers'; + import start from 'retrospring/common'; import initAnnouncements from 'retrospring/features/announcement'; import initAnswerbox from 'retrospring/features/answerbox/index'; @@ -26,4 +29,8 @@ document.addEventListener('DOMContentLoaded', initModeration); document.addEventListener('DOMContentLoaded', initMemes); document.addEventListener('turbo:load', initAnnouncements); document.addEventListener('turbo:load', initLocales); -document.addEventListener('turbo:load', initFront); \ No newline at end of file +document.addEventListener('turbo:load', initFront); + +window['Stimulus'] = Application.start(); +const context = require.context('../retrospring/controllers', true, /\.ts$/); +window['Stimulus'].load(definitionsFromContext(context)); diff --git a/babel.config.js b/babel.config.js index da4b00af..99520f36 100644 --- a/babel.config.js +++ b/babel.config.js @@ -35,12 +35,12 @@ module.exports = function(api) { exclude: ['transform-typeof-symbol'] } ], - ['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }] ].filter(Boolean), plugins: [ 'babel-plugin-macros', '@babel/plugin-syntax-dynamic-import', isTestEnv && 'babel-plugin-dynamic-import-node', + ["@babel/plugin-transform-typescript", { 'allExtensions': true, 'isTSX': true, 'allowDeclareFields': true }], '@babel/plugin-transform-destructuring', [ '@babel/plugin-proposal-class-properties', diff --git a/package.json b/package.json index bd8ed5bc..da0a9b9f 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ }, "dependencies": { "@babel/preset-typescript": "^7.18.6", + "@hotwired/stimulus": "^3.1.0", + "@hotwired/stimulus-webpack-helpers": "^1.0.1", "@hotwired/turbo-rails": "^7.1.3", "@melloware/coloris": "^0.16.0", "@rails/request.js": "^0.0.6", diff --git a/yarn.lock b/yarn.lock index f1057854..2cefe77d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1086,6 +1086,16 @@ resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210" integrity sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw== +"@hotwired/stimulus-webpack-helpers@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus-webpack-helpers/-/stimulus-webpack-helpers-1.0.1.tgz#4cd74487adeca576c9865ac2b9fe5cb20cef16dd" + integrity sha512-wa/zupVG0eWxRYJjC1IiPBdt3Lruv0RqGN+/DTMmUWUyMAEB27KXmVY6a8YpUVTM7QwVuaLNGW4EqDgrS2upXQ== + +"@hotwired/stimulus@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@hotwired/stimulus/-/stimulus-3.1.0.tgz#20215251e5afe6e0a3787285181ba1bfc9097df0" + integrity sha512-iDMHUhiEJ1xFeicyHcZQQgBzhtk5mPR0QZO3L6wtqzMsJEk2TKECuCQTGKjm+KJTHVY0dKq1dOOAWvODjpd2Mg== + "@hotwired/turbo-rails@^7.1.0", "@hotwired/turbo-rails@^7.1.3": version "7.1.3" resolved "https://registry.yarnpkg.com/@hotwired/turbo-rails/-/turbo-rails-7.1.3.tgz#a4e04ecb800a06e7f9aa6e298170fa4580b74216"