feat: create dynamic alias to use components from frontend vue apps
(cherry picked from commit f4f799f636410ac535ba119449b8bfbb81ffc562)
This commit is contained in:
parent
aa59703709
commit
c1b3a201a2
@ -2,11 +2,72 @@ import { defineConfig } from 'vite'
|
|||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import fs from 'fs'
|
||||||
import frappeui from 'frappe-ui/vite'
|
import frappeui from 'frappe-ui/vite'
|
||||||
import { VitePWA } from 'vite-plugin-pwa'
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
|
function appPath(app) {
|
||||||
|
const root = path.resolve(__dirname, '../..') // points to apps
|
||||||
|
const frontendPaths = [
|
||||||
|
// Standard frontend structure: appname/frontend/src
|
||||||
|
path.join(root, app, 'frontend', 'src'),
|
||||||
|
// Desk-based apps: appname/desk/src
|
||||||
|
path.join(root, app, 'desk', 'src'),
|
||||||
|
// Alternative frontend structures
|
||||||
|
path.join(root, app, 'client', 'src'),
|
||||||
|
path.join(root, app, 'ui', 'src'),
|
||||||
|
// Direct src structure: appname/src
|
||||||
|
path.join(root, app, 'src'),
|
||||||
|
]
|
||||||
|
return frontendPaths.find((srcPath) => fs.existsSync(srcPath)) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasApp(app) {
|
||||||
|
return fs.existsSync(appPath(app))
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of frontend apps used in this project
|
||||||
|
let apps = []
|
||||||
|
|
||||||
|
const alias = [
|
||||||
|
// Default "@" for this app
|
||||||
|
{
|
||||||
|
find: '@',
|
||||||
|
replacement: path.resolve(__dirname, 'src'),
|
||||||
|
},
|
||||||
|
|
||||||
|
// App-specific aliases like @helpdesk, @hrms, etc.
|
||||||
|
...apps.map((app) =>
|
||||||
|
hasApp(app)
|
||||||
|
? { find: `@${app}`, replacement: appPath(app) }
|
||||||
|
: { find: `@${app}`, replacement: `virtual:${app}` },
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
const defineFlags = Object.fromEntries(
|
||||||
|
apps.map((app) => [
|
||||||
|
`__HAS_${app.toUpperCase()}__`,
|
||||||
|
JSON.stringify(hasApp(app)),
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
|
||||||
|
const virtualStubPlugin = {
|
||||||
|
name: 'virtual-empty-modules',
|
||||||
|
resolveId(id) {
|
||||||
|
if (id.startsWith('virtual:')) return '\0' + id
|
||||||
|
},
|
||||||
|
load(id) {
|
||||||
|
if (id.startsWith('\0virtual:')) {
|
||||||
|
return 'export default {}; export const missing = true;'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Generated app aliases:', alias)
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
define: defineFlags,
|
||||||
plugins: [
|
plugins: [
|
||||||
frappeui({
|
frappeui({
|
||||||
frappeProxy: true,
|
frappeProxy: true,
|
||||||
@ -60,12 +121,9 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
virtualStubPlugin,
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: { alias },
|
||||||
alias: {
|
|
||||||
'@': path.resolve(__dirname, 'src'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: [
|
include: [
|
||||||
'feather-icons',
|
'feather-icons',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user