Files
core/vite-plugin.js
T

60 lines
3.1 KiB
JavaScript

// Vite integration for @boboko/core, mirroring how CoreServiceProvider owns
// and ships its own PHP wiring instead of making every consumer hand-copy
// it. A consuming app's vite.config.js just does:
//
// import { boboko } from '@boboko/core/vite-plugin'
// export default defineConfig({ plugins: [..., boboko()] })
//
// All of the settings below exist only because @boboko/core is typically
// installed as a local `file:../boboko-core` path dependency in dev
// (symlinked into node_modules by npm) rather than a real installed copy —
// see this package's own CONTRIBUTE.md.
export function boboko() {
return {
name: 'boboko-core',
config() {
return {
optimizeDeps: {
// @boboko/core is a live local dependency in dev, not a
// stable third-party lib. Vite's dependency pre-bundler
// otherwise caches it once under node_modules/.vite/deps
// and never re-scans it on a plain source edit, silently
// serving a stale bundle. Excluding it makes Vite treat
// it like first-party source: always transformed live.
exclude: ['@boboko/core'],
// Excluding @boboko/core above means its own dependencies
// (leaflet, @hotwired/stimulus) are no longer discovered
// by Vite's dependency scanner, since that scanner only
// crawls from already-optimized entry points. Without
// this, leaflet is served straight from its raw UMD
// source instead of the pre-bundled ESM shim, and
// `import L from 'leaflet'` fails with "does not provide
// an export named 'default'". Forces pre-bundling
// regardless of how they're reached in the import graph.
include: ['leaflet', '@hotwired/stimulus'],
},
resolve: {
// The local `file:../boboko-core` form installs as a
// symlink, same as npm always does for a local `file:`
// target. Without this, Vite resolves the symlink's bare
// imports relative to its real path outside the
// consumer's own root, where there's no node_modules,
// instead of from the symlink's location in the
// consumer's own node_modules. Harmless no-op against a
// real installed copy (tagged VCS release).
preserveSymlinks: true,
},
server: {
watch: {
// Same symlink as above: Vite/chokidar don't follow
// symlinks for watched files by default, so edits to
// core's source wouldn't otherwise trigger HMR.
// No-op against a real installed copy.
followSymlinks: true,
},
},
}
},
}
}