The doc on Vite plugins is here: <https://vite-kot...
# opensavvy
c
r
Is calling a
plugin()
function enough? I'm trying to use tailwindcss pluign and I've added:
Copy code
plugin("@tailwindcss/vite", "tailwindcss", "4.1.12")
But it doesn't work. I think the dependency is not added.
Copy code
> Task :viteRun FAILED
failed to load config from /home/rjaros/git/kilua-dev/build/vite/dev/vite.config.js
error when starting dev server:
Error: Cannot find module '@tailwindcss/vite'
I've managed to make tailwindcss plugin work by adding the npm dependency manually.
Copy code
implementation(npm("@tailwindcss/vite", "4.1.12"))
But I'm hitting the problem already described in https://gitlab.com/opensavvy/automation/kotlin-vite/-/issues/50
The plugins in ESM format don't work. Just changing the name of the configuration file to
vite.config.mjs
fixes that. No other changes are necessary.
c
I think the dependency is not added
Reproduced 😕 Tracking as https://gitlab.com/opensavvy/automation/kotlin-vite/-/issues/65
r
I've tested changing vite.config.js to mjs in the plugin sources and rebuild my local version. It builds and works perfectly. I think you should consider this change (or at least make it configurable).
c
Are there any downsides to naming it .mjs?
r
This is the recommended solution for node <= 22. https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only
KGP uses node 22
c
Sounds like there's no downside then, I'll make it .mjs in the next version
👍 1
Also, the name is configurable already;
Copy code
tasks.withType<WriteConfig>().configureEach {
    configurationFile.set(…)
}
r
This doesn't seem to work for me. Tried:
Copy code
tasks.withType<WriteConfig>().configureEach {
    configurationFile.set(project.layout.buildDirectory.dir("vite").map { it.file("vite.config.mjs") })
}
and got an error:
Copy code
A problem was found with the configuration of task ':viteRun' (type 'KotlinViteExec').
  - Type 'opensavvy.gradle.vite.kotlin.tasks.KotlinViteExec' property 'configurationFile' specifies file '/home/rjaros/git/kilua-dev/build/vite/dev/vite.config.js' which doesn't exist.
    
    Reason: An input file was expected to be present but it doesn't exist.
    
    Possible solutions:
      1. Make sure the file exists before the task is called.
      2. Make sure that the task which produces the file is declared as an input.
c
I see, the ViteExec tasks have a different config than the WriteConfig tasks… Should be fixed in the next version