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'
|
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'
|
2023-11-27 18:48:37 +03:00
|
|
|
const localServerPort = 8080
|
2023-09-22 06:43:25 +03:00
|
|
|
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-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-Embedder-Policy': 'require-corp',
|
|
|
|
'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-03-08 06:14:26 +03:00
|
|
|
...getDefines(localServerPort),
|
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),
|
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
|
|
|
})
|
|
|
|
|
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-03-06 12:53:12 +03:00
|
|
|
createGatewayServer(server.httpServer, undefined)
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|