diff --git a/package.json b/package.json index 1ae9212..fc5b022 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "kill": "fuser -k 5000/tcp", + "prebuild": "mkdir -p /tmp/dist || true", "build": "tsc -b --noCheck && vite build", "lint": "eslint . --fix", "lint:check": "eslint .", diff --git a/packages/spark-tools/src/sparkVitePlugin.ts b/packages/spark-tools/src/sparkVitePlugin.ts index d8500cd..22c961b 100644 --- a/packages/spark-tools/src/sparkVitePlugin.ts +++ b/packages/spark-tools/src/sparkVitePlugin.ts @@ -1,3 +1,7 @@ +import { mkdir } from 'fs/promises' +import { existsSync } from 'fs' +import { resolve } from 'path' + /** * Spark Vite Plugin * @@ -23,6 +27,17 @@ export default function sparkPlugin() { return html }, + async buildStart() { + const tmpDist = '/tmp/dist' + if (!existsSync(tmpDist)) { + try { + await mkdir(tmpDist, { recursive: true }) + } catch (err) { + console.warn('[spark-vite-plugin] Could not create /tmp/dist:', err) + } + } + }, + closeBundle() { // Build completed successfully // The Spark runtime may attempt to copy additional files after the build