zodiac-assets requires Vite to output a manifest file. Here's a minimal vite.config.js:
import { defineConfig } from "vite"
export default defineConfig({
build: {
outDir: "resources/myapp",
manifest: true,
rollupOptions: {
input: [
"src/app.js",
"src/style.css",
],
},
},
})
See examples/todo-app/vite.config.js for a working example.
| Setting | Purpose |
|---|---|
build.outDir | Where Vite writes built assets. Must be on your classpath. |
build.manifest | Generates .vite/manifest.json for asset resolution. |
build.rollupOptions.input | Entry points to bundle. |
Separate development and production Vite configurations allow different build behaviors.
import { defineConfig } from "vite"
export default defineConfig({
build: {
outDir: "resources/myapp",
manifest: true,
rollupOptions: {
input: ["src/app.js", "src/style.css"],
},
},
})
import { defineConfig, mergeConfig } from "vite"
import baseConfig from "./vite.config.js"
export default mergeConfig(baseConfig, defineConfig({
mode: "development",
build: {
watch: {},
},
}))
(let [dev? (= (System/getenv "ENV") "development")
assets-ext (z.assets/init
{:manifest-path "myapp/.vite/manifest.json"
:asset-resource-path "myapp"
:config-file (if dev?
"/app/vite.config.dev.js"
"/app/vite.config.js")
:build? true
:cache-manifest? (not dev?)})]
(z/start {:extensions [assets-ext]}))
For development, enable build.watch so Vite rebuilds when source files change:
build: {
watch: {}, // empty object enables watch mode
}
When using watch mode:
:cache-manifest? false so zodiac-assets reads fresh manifestsWith outDir: "resources/myapp", Vite creates:
resources/myapp/
.vite/
manifest.json # Asset manifest
assets/
app-[hash].js # Bundled JavaScript
style-[hash].css # Bundled CSS
Configure zodiac-assets to match:
(z.assets/init {:manifest-path "myapp/.vite/manifest.json"
:asset-resource-path "myapp"
...})
import { defineConfig } from "vite"
export default defineConfig({
build: {
outDir: "resources/myapp",
manifest: true,
rollupOptions: {
input: ["src/app.ts"],
},
},
})
Vite handles TypeScript compilation automatically.
Install Tailwind and configure postcss.config.js:
// postcss.config.js
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
No changes needed to vite.config.js—Vite picks up PostCSS config automatically.
rollupOptions: {
input: [
"src/admin.js",
"src/public.js",
"src/shared.css",
],
}
Each entry point gets its own manifest entry:
(assets "src/admin.js") ; => "/assets/admin-abc123.js"
(assets "src/public.js") ; => "/assets/public-def456.js"
Verify the manifest exists at your configured path:
(io/resource "myapp/.vite/manifest.json")
Common causes:
outDir doesn't match :manifest-pathThe asset name must match the original source path in rollupOptions.input:
;; If input is "src/app.js"
(assets "src/app.js") ; correct
(assets "app.js") ; returns nil
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |