enso/app/gui2/vite.ydoc-server-polyglot.config.ts
Dmitry Bushev 5995a00958
Run ydoc-server with GraalVM (#9528)
part of #7954

# Important Notes
The workflow is:
- `$ npm install` -- just in case
- `$ npm --workspace=enso-gui2 run build-ydoc-server-polyglot` -- build the `ydocServer.js` bundle
- `$ sbt ydoc-server/assembly` -- build the ydoc server jar
- `env POLYGLOT_YDOC_SERVER=true npm --workspace=enso-gui2 run dev` -- run the dev server with the polyglot ydoc server. Providing `POLYGLOT_YDOC_SERVER_DEBUG=true` env variable enables the chrome debugger
2024-05-02 06:28:57 +00:00

57 lines
1.4 KiB
TypeScript

import * as fs from 'node:fs'
import { fileURLToPath } from 'node:url'
import { defineConfig, type Plugin } from 'vite'
import defaultConfig from './vite.config'
const root = defaultConfig.root
const cacheDir = defaultConfig.cacheDir
const publicDir = defaultConfig.publicDir
const envDir = defaultConfig.envDir
const resolve = defaultConfig.resolve
export default defineConfig({
root,
cacheDir,
publicDir,
envDir,
resolve,
plugins: [usePolyglotFfi()],
define: {
...defaultConfig.define,
self: 'globalThis',
},
build: {
minify: false, // For debugging
emptyOutDir: true,
outDir: '../../lib/java/ydoc-server/target/classes/dist',
rollupOptions: {
input: {
ydocServer: fileURLToPath(new URL('ydoc-server/indexPolyglot.ts', import.meta.url)),
},
output: {
entryFileNames: `assets/[name].js`,
},
},
},
})
/**
* Use `ffiPolyglot` module as `ffi` interface during the build.
*/
function usePolyglotFfi(): Plugin {
const ffiPolyglot = fileURLToPath(new URL('./shared/ast/ffiPolyglot.ts', import.meta.url))
const ffiBackup = fileURLToPath(new URL('./shared/ast/ffiBackup.ts', import.meta.url))
const ffi = fileURLToPath(new URL('./shared/ast/ffi.ts', import.meta.url))
return {
name: 'use-polyglot-ffi',
options: () => {
fs.renameSync(ffi, ffiBackup)
fs.copyFileSync(ffiPolyglot, ffi)
},
buildEnd: () => {
fs.renameSync(ffiBackup, ffi)
},
}
}