created local deployment method that excludes crisp

This commit is contained in:
Carter 2026-04-27 14:09:50 -06:00
parent 5e52e096a2
commit 23de0a3bca
7 changed files with 160 additions and 38 deletions

View file

@ -1,12 +1,56 @@
import { defineConfig } from 'vite'
import { defineConfig, type Plugin, type UserConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import { VitePWA } from 'vite-plugin-pwa';
import * as path from 'path' // ✅ Import path module
import { readFileSync, renameSync, existsSync, unlinkSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
const rootDir = path.dirname(fileURLToPath(import.meta.url))
const NO_CRISP_MODE = 'nocrisp'
function useNoCrispIndexHtml (mode: string, command: string): Plugin {
if (mode !== NO_CRISP_MODE || command !== 'serve') {
return { name: 'use-local-index-html-noop' }
}
return {
name: 'use-local-index-html',
apply: 'serve',
transformIndexHtml: {
order: 'pre',
handler () {
return readFileSync(path.join(rootDir, 'indexLocal.html'), 'utf-8')
},
},
}
}
function emitNoCrispIndexAsIndexHtml (mode: string): Plugin {
if (mode !== NO_CRISP_MODE) {
return { name: 'emit-nocrisp-index-as-index-noop' }
}
return {
name: 'emit-nocrisp-index-as-index-html',
closeBundle () {
const outDir = path.join(rootDir, 'build')
const from = path.join(outDir, 'indexLocal.html')
const to = path.join(outDir, 'index.html')
if (existsSync(from)) {
if (existsSync(to)) unlinkSync(to)
renameSync(from, to)
}
},
}
}
// https://vitejs.dev/config/
export default defineConfig({
export default defineConfig(({ command, mode }): UserConfig => {
const useNoCrispIndex = mode === NO_CRISP_MODE
return {
plugins: [
useNoCrispIndexHtml(mode, command),
emitNoCrispIndexAsIndexHtml(mode),
react(),
tsconfigPaths(),
VitePWA({
@ -53,12 +97,15 @@ export default defineConfig({
target: 'esnext',
rollupOptions: {
input: {
main: path.resolve(__dirname, 'index.html')
}
main: path.join(
rootDir,
useNoCrispIndex ? 'indexLocal.html' : 'index.html'
),
},
}
},
esbuild: {
keepNames: true, // Prevent function name mangling
},
}
})