clojurescript 2025-09-19

Are there any public examples of bundling a vanilla CLJS project using vite? I’m hitting some kind of issue getting it to process a CLJS-generated require

I eventually got this building. Here for posterity in case it helps anyone else:

import { defineConfig } from 'vite';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export const baseConfig = {
  define: {
    'process.env.NODE_ENV': JSON.stringify('production')
  },
  build: {
    sourcemap: true,
    commonjsOptions: {
      include: ['node_modules/**', 'frontend/out/**'],
      requireReturnsDefault: 'auto'
    },
    rollupOptions: {
      plugins: [resolve()],
      external: []
    }
  }
};

🎉 2

org.clojure/clojurescript {:mvn/version “1.12.42”}, Vite 7.1.6

Probably these docs also apply to vite/esbuild? https://clojurescript.org/guides/webpack

not sure how full vite works, but we use vitest with webpack

could it be trying to lazy-load by statically analyzing import statements?

The docs do apply. This is mostly a vite configuration problem, but I’m hoping someone knows the incantation. More detail: Vite is ESM-only, but it has plugins for processing commonJS. My CLJS namespaces have (ns foo (:require “bar”)) The bundled JS includes a minified var a = require(“bar”); All of my searching indicates this should be possible, but nothing I’ve tried works

What build tool are you using? shadow-cljs at least definitely has an esm target that should emit imports not requires

Vanilla CLJS

I’ll look into shadow, thanks

Hrm that's annoying - I suppose it's a good idea support that output now.