2023-10-29 22:02:07 +03:00
|
|
|
/// <reference types="histoire" />
|
|
|
|
|
2023-09-05 01:27:33 +03:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
2024-03-08 06:14:26 +03:00
|
|
|
import { getDefines, readEnvironmentFromFile } from 'enso-common/src/appConfig'
|
2024-05-02 09:28:57 +03:00
|
|
|
import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process'
|
|
|
|
import { existsSync } from 'node:fs'
|
2023-09-22 06:43:25 +03:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2023-09-05 01:27:33 +03:00
|
|
|
import postcssNesting from 'postcss-nesting'
|
2023-09-22 06:43:25 +03:00
|
|
|
import tailwindcss from 'tailwindcss'
|
|
|
|
import tailwindcssNesting from 'tailwindcss/nesting'
|
2023-10-07 23:57:47 +03:00
|
|
|
import { defineConfig, type Plugin } from 'vite'
|
2023-11-30 16:20:09 +03:00
|
|
|
// @ts-expect-error
|
2024-03-08 06:14:26 +03:00
|
|
|
import * as tailwindConfig from 'enso-dashboard/tailwind.config'
|
2023-09-22 06:43:25 +03:00
|
|
|
import { createGatewayServer } from './ydoc-server'
|
|
|
|
const projectManagerUrl = 'ws://127.0.0.1:30535'
|
2023-09-05 01:27:33 +03:00
|
|
|
|
2023-12-21 18:04:30 +03:00
|
|
|
const IS_CLOUD_BUILD = process.env.CLOUD_BUILD === 'true'
|
2024-05-02 09:28:57 +03:00
|
|
|
const IS_POLYGLOT_YDOC_SERVER_DEBUG = process.env.POLYGLOT_YDOC_SERVER_DEBUG === 'true'
|
|
|
|
const IS_POLYGLOT_YDOC_SERVER =
|
|
|
|
process.env.POLYGLOT_YDOC_SERVER === 'true' || IS_POLYGLOT_YDOC_SERVER_DEBUG
|
2023-12-21 18:04:30 +03:00
|
|
|
|
2024-03-08 06:14:26 +03:00
|
|
|
await readEnvironmentFromFile()
|
|
|
|
|
2024-03-14 20:05:26 +03:00
|
|
|
const entrypoint = process.env.E2E === 'true' ? './src/e2e-entrypoint.ts' : './src/entrypoint.ts'
|
|
|
|
|
2023-09-05 01:27:33 +03:00
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default defineConfig({
|
2024-03-27 17:42:23 +03:00
|
|
|
root: fileURLToPath(new URL('.', import.meta.url)),
|
|
|
|
cacheDir: fileURLToPath(new URL('../../node_modules/.cache/vite', import.meta.url)),
|
|
|
|
publicDir: fileURLToPath(new URL('./public', import.meta.url)),
|
|
|
|
envDir: fileURLToPath(new URL('.', import.meta.url)),
|
|
|
|
plugins: [
|
|
|
|
vue(),
|
|
|
|
gatewayServer(),
|
|
|
|
...(process.env.ELECTRON_DEV_MODE === 'true' ?
|
|
|
|
[
|
|
|
|
(await import('@vitejs/plugin-react')).default({
|
|
|
|
include: fileURLToPath(new URL('../ide-desktop/lib/dashboard/**/*.tsx', import.meta.url)),
|
|
|
|
babel: { plugins: ['@babel/plugin-syntax-import-assertions'] },
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
: process.env.NODE_ENV === 'development' ? [await projectManagerShim()]
|
|
|
|
: []),
|
|
|
|
],
|
2023-09-22 06:43:25 +03:00
|
|
|
optimizeDeps: {
|
2024-03-27 17:42:23 +03:00
|
|
|
entries: fileURLToPath(new URL('./index.html', import.meta.url)),
|
2023-09-22 06:43:25 +03:00
|
|
|
},
|
2023-11-20 14:32:40 +03:00
|
|
|
server: {
|
|
|
|
headers: {
|
|
|
|
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
|
|
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
|
|
},
|
|
|
|
},
|
2023-09-05 01:27:33 +03:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
2024-03-14 20:05:26 +03:00
|
|
|
'/src/entrypoint.ts': fileURLToPath(new URL(entrypoint, import.meta.url)),
|
2023-09-07 15:54:01 +03:00
|
|
|
shared: fileURLToPath(new URL('./shared', import.meta.url)),
|
2023-09-05 01:27:33 +03:00
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
|
|
},
|
|
|
|
},
|
2023-09-22 06:43:25 +03:00
|
|
|
define: {
|
2024-05-22 16:56:42 +03:00
|
|
|
...getDefines(),
|
2023-12-21 18:04:30 +03:00
|
|
|
IS_CLOUD_BUILD: JSON.stringify(IS_CLOUD_BUILD),
|
2023-09-22 06:43:25 +03:00
|
|
|
PROJECT_MANAGER_URL: JSON.stringify(projectManagerUrl),
|
2024-05-02 09:28:57 +03:00
|
|
|
YDOC_SERVER_URL: IS_POLYGLOT_YDOC_SERVER ? JSON.stringify('defined') : undefined,
|
2023-10-11 16:04:38 +03:00
|
|
|
RUNNING_VITEST: false,
|
2023-10-07 23:57:47 +03:00
|
|
|
'import.meta.vitest': false,
|
2024-03-08 06:14:26 +03:00
|
|
|
// Single hardcoded usage of `global` in aws-amplify.
|
2023-10-07 23:57:47 +03:00
|
|
|
'global.TYPED_ARRAY_SUPPORT': true,
|
2023-09-22 06:43:25 +03:00
|
|
|
},
|
|
|
|
assetsInclude: ['**/*.yaml', '**/*.svg'],
|
2023-09-05 01:27:33 +03:00
|
|
|
css: {
|
|
|
|
postcss: {
|
2023-11-30 16:20:09 +03:00
|
|
|
plugins: [
|
|
|
|
tailwindcssNesting(postcssNesting()),
|
|
|
|
tailwindcss({
|
|
|
|
...tailwindConfig.default,
|
|
|
|
content: tailwindConfig.default.content.map((glob: string) =>
|
2024-03-27 17:42:23 +03:00
|
|
|
glob.replace(
|
|
|
|
/^[.][/]/,
|
|
|
|
fileURLToPath(new URL('../ide-desktop/lib/dashboard/', import.meta.url)),
|
|
|
|
),
|
2023-11-30 16:20:09 +03:00
|
|
|
),
|
|
|
|
}),
|
|
|
|
],
|
2023-09-05 01:27:33 +03:00
|
|
|
},
|
|
|
|
},
|
2023-09-22 06:43:25 +03:00
|
|
|
build: {
|
|
|
|
// dashboard chunk size is larger than the default warning limit
|
|
|
|
chunkSizeWarningLimit: 700,
|
2023-10-07 23:57:47 +03:00
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
manualChunks: {
|
|
|
|
fontawesome: ['@fortawesome/react-fontawesome', '@fortawesome/free-brands-svg-icons'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-09-22 06:43:25 +03:00
|
|
|
},
|
2023-09-05 01:27:33 +03:00
|
|
|
})
|
|
|
|
|
2024-05-02 09:28:57 +03:00
|
|
|
let ydocServer: ChildProcessWithoutNullStreams | null
|
2023-09-22 06:43:25 +03:00
|
|
|
function gatewayServer(): Plugin {
|
2023-09-05 01:27:33 +03:00
|
|
|
return {
|
2023-09-22 06:43:25 +03:00
|
|
|
name: 'gateway-server',
|
2023-09-05 01:27:33 +03:00
|
|
|
configureServer(server) {
|
|
|
|
if (server.httpServer == null) return
|
2023-09-22 06:43:25 +03:00
|
|
|
|
2024-05-02 09:28:57 +03:00
|
|
|
if (IS_POLYGLOT_YDOC_SERVER) {
|
|
|
|
const ydocServerJar = fileURLToPath(
|
|
|
|
new URL(
|
|
|
|
'../../lib/java/ydoc-server/target/ydoc-server-assembly-0.1.0-SNAPSHOT.jar',
|
|
|
|
import.meta.url,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
const runYdocServer = () => {
|
|
|
|
const args = []
|
|
|
|
if (IS_POLYGLOT_YDOC_SERVER_DEBUG) {
|
|
|
|
args.push('-DinspectPort=34567')
|
|
|
|
}
|
|
|
|
args.push('-jar', ydocServerJar)
|
|
|
|
ydocServer = spawn('java', args)
|
|
|
|
if (IS_POLYGLOT_YDOC_SERVER_DEBUG) {
|
|
|
|
ydocServer.stdout.on('data', (data) => console.log(`ydoc: ${data}`))
|
|
|
|
}
|
|
|
|
ydocServer.stderr.on('data', (data) => console.log(`ydoc: ${data}`))
|
|
|
|
}
|
|
|
|
if (!existsSync(ydocServerJar)) {
|
|
|
|
const cwd = fileURLToPath(new URL('../..', import.meta.url))
|
|
|
|
const sbt = spawn('sbt', ['ydoc-server/assembly'], { cwd })
|
|
|
|
sbt.stdout.on('data', (data) => console.log(`sbt: ${data}`))
|
|
|
|
sbt.on('exit', runYdocServer)
|
|
|
|
} else {
|
|
|
|
runYdocServer()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
createGatewayServer(server.httpServer, undefined)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
buildEnd() {
|
|
|
|
if (ydocServer == null) return
|
|
|
|
|
|
|
|
ydocServer.kill('SIGTERM')
|
2023-09-05 01:27:33 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2024-03-27 17:42:23 +03:00
|
|
|
|
|
|
|
async function projectManagerShim(): Promise<Plugin> {
|
|
|
|
const module = await import(
|
|
|
|
'../ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware'
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
name: 'project-manager-shim',
|
|
|
|
configureServer(server) {
|
|
|
|
server.middlewares.use(module.default)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|