2024-07-10 16:44:39 +00:00
import { cloudflareDevProxyVitePlugin as remixCloudflareDevProxy , vitePlugin as remixVitePlugin } from '@remix-run/dev' ;
import UnoCSS from 'unocss/vite' ;
2024-10-07 14:20:42 +00:00
import { defineConfig , type ViteDevServer } from 'vite' ;
2024-07-17 18:54:46 +00:00
import { nodePolyfills } from 'vite-plugin-node-polyfills' ;
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules' ;
2024-07-10 16:44:39 +00:00
import tsconfigPaths from 'vite-tsconfig-paths' ;
2025-01-06 13:48:42 +00:00
import * as dotenv from 'dotenv' ;
2024-12-20 19:33:28 +00:00
import { execSync } from 'child_process' ;
2025-01-30 16:17:36 +00:00
import { readFileSync } from 'fs' ;
import { join } from 'path' ;
2024-12-20 19:33:28 +00:00
2025-01-06 13:48:42 +00:00
dotenv . config ( ) ;
2025-01-30 16:17:36 +00:00
// Get detailed git info with fallbacks
const getGitInfo = ( ) = > {
2024-12-20 19:33:28 +00:00
try {
2025-01-30 16:17:36 +00:00
return {
commitHash : execSync ( 'git rev-parse --short HEAD' ) . toString ( ) . trim ( ) ,
branch : execSync ( 'git rev-parse --abbrev-ref HEAD' ) . toString ( ) . trim ( ) ,
commitTime : execSync ( 'git log -1 --format=%cd' ) . toString ( ) . trim ( ) ,
author : execSync ( 'git log -1 --format=%an' ) . toString ( ) . trim ( ) ,
email : execSync ( 'git log -1 --format=%ae' ) . toString ( ) . trim ( ) ,
remoteUrl : execSync ( 'git config --get remote.origin.url' ) . toString ( ) . trim ( ) ,
repoName : execSync ( 'git config --get remote.origin.url' )
. toString ( )
. trim ( )
. replace ( /^.*github.com[:/]/ , '' )
. replace ( /\.git$/ , '' ) ,
} ;
2024-12-20 19:33:28 +00:00
} catch {
2025-01-30 16:17:36 +00:00
return {
commitHash : 'no-git-info' ,
branch : 'unknown' ,
commitTime : 'unknown' ,
author : 'unknown' ,
email : 'unknown' ,
remoteUrl : 'unknown' ,
repoName : 'unknown' ,
} ;
2024-12-20 19:33:28 +00:00
}
} ;
2025-01-30 16:17:36 +00:00
// Read package.json with detailed dependency info
const getPackageJson = ( ) = > {
try {
const pkgPath = join ( process . cwd ( ) , 'package.json' ) ;
const pkg = JSON . parse ( readFileSync ( pkgPath , 'utf-8' ) ) ;
return {
name : pkg.name ,
description : pkg.description ,
license : pkg.license ,
dependencies : pkg.dependencies || { } ,
devDependencies : pkg.devDependencies || { } ,
peerDependencies : pkg.peerDependencies || { } ,
optionalDependencies : pkg.optionalDependencies || { } ,
} ;
} catch {
return {
name : 'bolt.diy' ,
description : 'A DIY LLM interface' ,
license : 'MIT' ,
dependencies : { } ,
devDependencies : { } ,
peerDependencies : { } ,
optionalDependencies : { } ,
} ;
}
} ;
const pkg = getPackageJson ( ) ;
const gitInfo = getGitInfo ( ) ;
2024-07-10 16:44:39 +00:00
export default defineConfig ( ( config ) = > {
return {
2024-12-20 19:33:28 +00:00
define : {
2025-01-30 16:17:36 +00:00
__COMMIT_HASH : JSON.stringify ( gitInfo . commitHash ) ,
__GIT_BRANCH : JSON.stringify ( gitInfo . branch ) ,
__GIT_COMMIT_TIME : JSON.stringify ( gitInfo . commitTime ) ,
__GIT_AUTHOR : JSON.stringify ( gitInfo . author ) ,
__GIT_EMAIL : JSON.stringify ( gitInfo . email ) ,
__GIT_REMOTE_URL : JSON.stringify ( gitInfo . remoteUrl ) ,
__GIT_REPO_NAME : JSON.stringify ( gitInfo . repoName ) ,
2024-12-20 20:54:57 +00:00
__APP_VERSION : JSON.stringify ( process . env . npm_package_version ) ,
2025-01-30 16:17:36 +00:00
__PKG_NAME : JSON.stringify ( pkg . name ) ,
__PKG_DESCRIPTION : JSON.stringify ( pkg . description ) ,
__PKG_LICENSE : JSON.stringify ( pkg . license ) ,
__PKG_DEPENDENCIES : JSON.stringify ( pkg . dependencies ) ,
__PKG_DEV_DEPENDENCIES : JSON.stringify ( pkg . devDependencies ) ,
__PKG_PEER_DEPENDENCIES : JSON.stringify ( pkg . peerDependencies ) ,
__PKG_OPTIONAL_DEPENDENCIES : JSON.stringify ( pkg . optionalDependencies ) ,
2025-02-17 02:10:15 +00:00
'module' : { } ,
2024-12-20 19:33:28 +00:00
} ,
2024-07-17 19:31:47 +00:00
build : {
target : 'esnext' ,
} ,
2024-07-10 16:44:39 +00:00
plugins : [
2024-07-17 18:54:46 +00:00
nodePolyfills ( {
2025-01-06 13:48:42 +00:00
include : [ 'path' , 'buffer' , 'process' ] ,
2024-07-17 18:54:46 +00:00
} ) ,
2024-07-10 16:44:39 +00:00
config . mode !== 'test' && remixCloudflareDevProxy ( ) ,
remixVitePlugin ( {
future : {
v3_fetcherPersist : true ,
v3_relativeSplatPath : true ,
2024-12-15 20:20:22 +00:00
v3_throwAbortReason : true ,
2025-01-28 10:39:12 +00:00
v3_lazyRouteDiscovery : true ,
2024-07-10 16:44:39 +00:00
} ,
} ) ,
UnoCSS ( ) ,
tsconfigPaths ( ) ,
2024-10-07 14:20:42 +00:00
chrome129IssuePlugin ( ) ,
2024-07-17 18:54:46 +00:00
config . mode === 'production' && optimizeCssModules ( { apply : 'build' } ) ,
2024-07-10 16:44:39 +00:00
] ,
2025-01-28 10:39:12 +00:00
envPrefix : [
'VITE_' ,
'OPENAI_LIKE_API_BASE_URL' ,
'OLLAMA_API_BASE_URL' ,
'LMSTUDIO_API_BASE_URL' ,
'TOGETHER_API_BASE_URL' ,
] ,
2024-10-21 22:27:29 +00:00
css : {
preprocessorOptions : {
scss : {
api : 'modern-compiler' ,
} ,
} ,
} ,
2024-07-10 16:44:39 +00:00
} ;
} ) ;
2024-10-07 14:20:42 +00:00
function chrome129IssuePlugin() {
return {
name : 'chrome129IssuePlugin' ,
configureServer ( server : ViteDevServer ) {
server . middlewares . use ( ( req , res , next ) = > {
const raw = req . headers [ 'user-agent' ] ? . match ( /Chrom(e|ium)\/([0-9]+)\./ ) ;
if ( raw ) {
const version = parseInt ( raw [ 2 ] , 10 ) ;
if ( version === 129 ) {
res . setHeader ( 'content-type' , 'text/html' ) ;
res . end (
'<body><h1>Please use Chrome Canary for testing.</h1><p>Chrome 129 has an issue with JavaScript modules & Vite local development, see <a href="https://github.com/stackblitz/bolt.new/issues/86#issuecomment-2395519258">for more information.</a></p><p><b>Note:</b> This only impacts <u>local development</u>. `pnpm run build` and `pnpm run start` will work fine in this browser.</p></body>' ,
) ;
return ;
}
}
next ( ) ;
} ) ;
} ,
} ;
}