yunohost-admin/app/vite.config.js

86 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-02-24 18:25:12 +01:00
import { fileURLToPath, URL } from 'url'
import { defineConfig, loadEnv } from 'vite'
import fs from 'fs'
import vue from '@vitejs/plugin-vue2'
export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd())
const config = {
define: {
// fake process.env for some deps
2024-02-24 18:25:12 +01:00
'process.env': {},
},
2024-02-24 18:25:12 +01:00
resolve: {
alias: [
// this is required for the SCSS modules imports with `~` (node_modules)
{ find: /^~(.*)$/, replacement: '$1' },
2024-02-24 18:25:12 +01:00
{
find: '@',
replacement: fileURLToPath(new URL('./src', import.meta.url)),
},
],
},
css: {
preprocessorOptions: {
scss: {
// To auto inject scss variables into componentns scope
additionalData: `
@import "@/scss/_variables.scss";
2024-02-24 18:25:12 +01:00
`,
},
},
},
2024-02-24 18:25:12 +01:00
plugins: [vue()],
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
// Circular import problems, this will merge vue/vuex/etc. and api together
if (!id.includes('node_modules') && id.includes('api/')) {
2024-02-24 18:25:12 +01:00
return 'core'
}
2024-02-24 18:25:12 +01:00
},
},
},
},
}
if (mode === 'production') {
return {
...config,
base: '/yunohost/admin',
}
} else if (mode === 'development') {
return {
...config,
server: {
port: 8080,
host: env.VITE_IP,
https: {
// Use already created cert from yunohost instance
key: fs.readFileSync('/etc/yunohost/certs/yunohost.org/key.pem'),
cert: fs.readFileSync('/etc/yunohost/certs/yunohost.org/crt.pem'),
},
fs: {
// Needed for special ynh-dev context where node_modules is symlinked
allow: [
'/ynh-dev/yunohost-admin/app',
2024-02-24 18:25:12 +01:00
'/var/cache/ynh-dev/yunohost-admin/node_modules',
],
},
proxy: {
'/yunohost': {
target: `https://${env.VITE_IP}`,
ws: true,
logLevel: 'info',
secure: false,
},
},
2024-02-24 18:25:12 +01:00
},
}
}
})