diff --git a/Jenkinsfile b/Jenkinsfile index fe06e76..9b9251a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' } } } diff --git a/package.json b/package.json index b4d6078..46fc6d3 100644 --- a/package.json +++ b/package.json @@ -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": [ { diff --git a/vite.config.js b/vite.config.js index ceccabf..78b0113 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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,