Fixed cloudflare build.
Some checks failed
farmcontrol/farmcontrol-ui/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-03-01 02:02:38 +00:00
parent 075dfc6481
commit 96f1ab077c
3 changed files with 24 additions and 5 deletions

4
Jenkinsfile vendored
View File

@ -20,7 +20,7 @@ def deploy() {
stage('Build (Ubuntu)') {
nodejs(nodeJSInstallationName: 'Node23') {
sh 'NODE_ENV=production pnpm build'
sh 'NODE_ENV=production pnpm build:cloudflare'
}
}
@ -28,7 +28,7 @@ def deploy() {
nodejs(nodeJSInstallationName: 'Node23') {
// Deploy to Cloudflare Pages using wrangler
withCredentials([string(credentialsId: 'cloudflare-api-token', variable: 'CLOUDFLARE_API_TOKEN')]) {
sh 'pnpm wrangler pages deploy build'
sh 'pnpm wrangler pages deploy build --branch main'
}
}
}

View File

@ -72,7 +72,8 @@
"build": "vite build",
"dev:electron": "concurrently \"cross-env NODE_ENV=development vite --no-open\" \"cross-env ELECTRON_START_URL=http://localhost:5780 cross-env NODE_ENV=development electron public/electron.js\"",
"build:electron": "vite build && electron-builder",
"deploy": "vite build && wrangler pages deploy --branch main"
"build:cloudflare": "cross-env VITE_DEPLOY_TARGET=cloudflare vite build",
"deploy": "npm run build:cloudflare && wrangler pages deploy --branch main"
},
"eslintConfig": {
"extends": [
@ -142,6 +143,7 @@
],
"mergeASARs": true,
"x64ArchFiles": "**/node_modules/@esbuild/darwin-x64/**",
"singleArchFiles": "**/node_modules/@antv/**",
"extendInfo": {
"CFBundleURLTypes": [
{

View File

@ -10,8 +10,10 @@ import { visualizer } from 'rollup-plugin-visualizer'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const isCloudflare = process.env.VITE_DEPLOY_TARGET === 'cloudflare'
export default defineConfig({
base: './', // Required for Electron file:// protocol - absolute paths fail
base: isCloudflare ? '/' : './', // Cloudflare Pages needs absolute paths; Electron needs relative for file://
resolve: {
alias: {
three: path.resolve(__dirname, 'node_modules/three')
@ -20,7 +22,22 @@ export default defineConfig({
optimizeDeps: {
include: ['@ant-design/icons']
},
plugins: [react(), svgo(), svgr(), eslintPlugin(), visualizer()],
plugins: [
react(),
svgo(),
svgr(),
eslintPlugin(),
visualizer(),
// Transform index.html paths to absolute when building for Cloudflare Pages
isCloudflare && {
name: 'cloudflare-html-paths',
transformIndexHtml(html) {
return html
.replace(/href="\.\//g, 'href="/')
.replace(/src="\.\//g, 'src="/')
}
}
].filter(Boolean),
build: {
outDir: 'build',
chunkSizeWarningLimit: 2000,