c6295b48a5
The @nextcloud/vue library (v9.x) requires appName and appVersion to be defined as global constants at build time. Without these, the library logs an error: "The '@nextcloud/vue' library was used without setting / replacing the 'appName'." This fix reads the app ID and version from appinfo/info.xml and injects them via Vite's define option, matching how @nextcloud/webpack-vue-config handles this for webpack-based apps. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
import { defineConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import { resolve } from 'path'
|
|
import { readFileSync } from 'fs'
|
|
|
|
// Read app info from info.xml for @nextcloud/vue
|
|
const infoXml = readFileSync(resolve(__dirname, 'appinfo/info.xml'), 'utf-8')
|
|
const appName = infoXml.match(/<id>([^<]+)<\/id>/)?.[1] || 'astrolabe'
|
|
const appVersion = infoXml.match(/<version>([^<]+)<\/version>/)?.[1] || ''
|
|
|
|
export default defineConfig({
|
|
plugins: [vue()],
|
|
define: {
|
|
appName: JSON.stringify(appName),
|
|
appVersion: JSON.stringify(appVersion),
|
|
},
|
|
build: {
|
|
outDir: '.',
|
|
emptyOutDir: false,
|
|
cssCodeSplit: false, // Bundle all CSS into entry points (Nextcloud doesn't load CSS chunks)
|
|
rollupOptions: {
|
|
input: {
|
|
'astrolabe-main': resolve(__dirname, 'src/main.js'),
|
|
'astrolabe-adminSettings': resolve(__dirname, 'src/adminSettings.js'),
|
|
'astrolabe-personalSettings': resolve(__dirname, 'src/personalSettings.js'),
|
|
},
|
|
output: {
|
|
entryFileNames: 'js/[name].mjs',
|
|
chunkFileNames: 'js/[name]-[hash].chunk.mjs',
|
|
assetFileNames: (assetInfo) => {
|
|
// With cssCodeSplit:false, all CSS goes to a single file
|
|
// Name it astrolabe-main.css to match Nextcloud's Util::addStyle expectation
|
|
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
|
|
return 'css/astrolabe-main.css';
|
|
}
|
|
return 'js/[name][extname]';
|
|
},
|
|
},
|
|
},
|
|
sourcemap: true,
|
|
minify: 'terser',
|
|
},
|
|
})
|