Created
October 24, 2023 04:41
-
-
Save mareksotak/5406ad5a8c3ca68003124b5c32d48b38 to your computer and use it in GitHub Desktop.
Rails 7 - Vue 3 - Stimulus controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller } from "@hotwired/stimulus" | |
import { createApp } from "vue" | |
import App from "../hello/App.vue" | |
export default class extends Controller { | |
connect() { | |
this.app = createApp(App); | |
this.app.mount(this.element); | |
} | |
disconnect() { | |
this.app.unmount(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-controller="hello"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
import rails from "esbuild-rails" | |
import vuePlugin from "esbuild-plugin-vue3" // <------ yarn add esbuild-plugin-vue3 | |
import chokidar from "chokidar" | |
... | |
const watchDirectories = [ | |
"./app/javascript/**/*.js", | |
"./app/javascript/**/*.vue", // <------ To watch for changes in .vue templates | |
"./app/views/**/*.html.erb", | |
"./app/assets/builds/**/*.css", | |
"./config/locales/**/*.yml", | |
] | |
const config = { | |
absWorkingDir: path.join(process.cwd(), "app/javascript"), | |
bundle: true, | |
entryPoints: entryPoints, | |
minify: process.env.RAILS_ENV == "production", | |
outdir: path.join(process.cwd(), "app/assets/builds"), | |
plugins: [rails(), vuePlugin()], // <------ add vuePlugin() | |
sourcemap: process.env.RAILS_ENV != "production" | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
content: [ | |
'./app/components/**/*.rb', | |
'./app/helpers/**/*.rb', | |
'./app/javascript/**/*.js', | |
'./app/javascript/**/*.vue', // <------ To include classes from .vue templates | |
'./app/views/**/*.erb', | |
.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment