2023-10-29 22:02:07 +03:00
|
|
|
/// <reference types="histoire" />
|
|
|
|
|
2024-06-07 04:48:11 +03:00
|
|
|
import react from '@vitejs/plugin-react'
|
2023-09-05 01:27:33 +03:00
|
|
|
import vue from '@vitejs/plugin-vue'
|
2024-10-11 21:23:02 +03:00
|
|
|
import { COOP_COEP_CORP_HEADERS } from 'enso-common'
|
2024-03-08 06:14:26 +03:00
|
|
|
import { getDefines, readEnvironmentFromFile } from 'enso-common/src/appConfig'
|
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'
|
2024-06-27 18:11:28 +03:00
|
|
|
import VueDevTools from 'vite-plugin-vue-devtools'
|
2024-08-08 15:12:05 +03:00
|
|
|
import wasm from 'vite-plugin-wasm'
|
2024-10-11 21:23:02 +03:00
|
|
|
import tailwindConfig from './tailwind.config'
|
2023-09-05 01:27:33 +03:00
|
|
|
|
2024-09-20 19:31:45 +03:00
|
|
|
const dynHostnameWsUrl = (port: number) => JSON.stringify(`ws://__HOSTNAME__:${port}`)
|
|
|
|
const projectManagerUrl = dynHostnameWsUrl(process.env.E2E === 'true' ? 30536 : 30535)
|
2023-12-21 18:04:30 +03:00
|
|
|
const IS_CLOUD_BUILD = process.env.CLOUD_BUILD === 'true'
|
2024-08-12 19:52:44 +03:00
|
|
|
const YDOC_SERVER_URL =
|
2024-09-20 19:31:45 +03:00
|
|
|
process.env.ENSO_POLYGLOT_YDOC_SERVER ? JSON.stringify(process.env.ENSO_POLYGLOT_YDOC_SERVER)
|
|
|
|
: process.env.NODE_ENV === 'development' ? dynHostnameWsUrl(5976)
|
|
|
|
: undefined
|
2023-12-21 18:04:30 +03:00
|
|
|
|
2024-03-08 06:14:26 +03:00
|
|
|
await readEnvironmentFromFile()
|
|
|
|
|
2024-10-11 21:23:02 +03:00
|
|
|
const entrypoint =
|
|
|
|
process.env.E2E === 'true' ? './src/project-view/e2e-entrypoint.ts' : './src/entrypoint.ts'
|
2024-03-14 20:05:26 +03:00
|
|
|
|
2024-10-30 16:48:59 +03:00
|
|
|
// NOTE(Frizi): This rename is for the sake of forward compatibility with not yet merged config refactor on bazel branch,
|
|
|
|
// and because Vite's HTML env replacements only work with import.meta.env variables, not defines.
|
|
|
|
process.env.ENSO_IDE_VERSION = process.env.ENSO_CLOUD_DASHBOARD_VERSION
|
|
|
|
|
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: [
|
2024-08-08 15:12:05 +03:00
|
|
|
wasm(),
|
2024-09-20 19:31:45 +03:00
|
|
|
...(process.env.NODE_ENV === 'development' ? [await VueDevTools()] : []),
|
2024-09-23 21:31:26 +03:00
|
|
|
vue({
|
|
|
|
customElement: ['**/components/visualizations/**', '**/components/shared/**'],
|
|
|
|
template: {
|
|
|
|
compilerOptions: {
|
|
|
|
isCustomElement: (tag) => tag.startsWith('enso-'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
2024-06-07 04:48:11 +03:00
|
|
|
react({
|
2024-10-11 21:23:02 +03:00
|
|
|
include: fileURLToPath(new URL('./src/dashboard/**/*.tsx', import.meta.url)),
|
2024-10-31 15:10:22 +03:00
|
|
|
babel: {
|
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-syntax-import-attributes',
|
|
|
|
['babel-plugin-react-compiler', { target: '18' }],
|
|
|
|
],
|
|
|
|
},
|
2024-06-07 04:48:11 +03:00
|
|
|
}),
|
|
|
|
...(process.env.NODE_ENV === 'development' ? [await projectManagerShim()] : []),
|
2024-03-27 17:42:23 +03:00
|
|
|
],
|
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: {
|
2024-10-11 21:23:02 +03:00
|
|
|
headers: Object.fromEntries(COOP_COEP_CORP_HEADERS),
|
2024-09-20 19:31:45 +03:00
|
|
|
...(process.env.GUI_HOSTNAME ? { host: process.env.GUI_HOSTNAME } : {}),
|
2023-11-20 14:32:40 +03:00
|
|
|
},
|
2023-09-05 01:27:33 +03:00
|
|
|
resolve: {
|
2024-08-08 15:12:05 +03:00
|
|
|
conditions: ['source'],
|
2023-09-05 01:27:33 +03:00
|
|
|
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)),
|
2024-10-11 21:23:02 +03:00
|
|
|
'@': fileURLToPath(new URL('./src/project-view', import.meta.url)),
|
|
|
|
'#': fileURLToPath(new URL('./src/dashboard', import.meta.url)),
|
2023-09-05 01:27:33 +03:00
|
|
|
},
|
|
|
|
},
|
2024-10-30 16:48:59 +03:00
|
|
|
envPrefix: 'ENSO_IDE_',
|
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),
|
2024-09-20 19:31:45 +03:00
|
|
|
PROJECT_MANAGER_URL: projectManagerUrl,
|
|
|
|
YDOC_SERVER_URL: YDOC_SERVER_URL,
|
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
|
|
|
},
|
2024-07-12 13:45:57 +03:00
|
|
|
esbuild: {
|
|
|
|
dropLabels: process.env.NODE_ENV === 'development' ? [] : ['DEV'],
|
2024-08-08 15:12:05 +03:00
|
|
|
supported: {
|
|
|
|
'top-level-await': true,
|
|
|
|
},
|
2024-07-12 13:45:57 +03:00
|
|
|
},
|
2024-10-11 21:23:02 +03:00
|
|
|
assetsInclude: ['**/*.svg'],
|
2023-09-05 01:27:33 +03:00
|
|
|
css: {
|
|
|
|
postcss: {
|
2024-10-11 21:23:02 +03:00
|
|
|
plugins: [tailwindcssNesting(postcssNesting()), tailwindcss(tailwindConfig)],
|
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-09-05 01:27:33 +03:00
|
|
|
})
|
2024-03-27 17:42:23 +03:00
|
|
|
async function projectManagerShim(): Promise<Plugin> {
|
2024-07-17 12:10:42 +03:00
|
|
|
const module = await import('./project-manager-shim-middleware')
|
2024-03-27 17:42:23 +03:00
|
|
|
return {
|
|
|
|
name: 'project-manager-shim',
|
|
|
|
configureServer(server) {
|
|
|
|
server.middlewares.use(module.default)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|