2023-07-20 16:43:40 +03:00
|
|
|
import { createLibConfig } from '@nextcloud/vite-config'
|
2023-07-13 02:57:39 +03:00
|
|
|
import { readdirSync, readFileSync } from 'fs'
|
2023-08-16 23:48:56 +03:00
|
|
|
import { po as poParser } from 'gettext-parser'
|
2023-08-20 22:53:05 +03:00
|
|
|
import { defineConfig, type UserConfigFn } from 'vite'
|
2023-07-13 02:57:39 +03:00
|
|
|
|
2023-07-20 16:43:40 +03:00
|
|
|
const translations = readdirSync('./l10n')
|
2023-07-13 02:57:39 +03:00
|
|
|
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
|
|
|
|
.map(file => {
|
|
|
|
const path = './l10n/' + file
|
|
|
|
const locale = file.slice(0, -'.pot'.length)
|
|
|
|
|
2023-07-20 16:43:40 +03:00
|
|
|
const po = readFileSync(path)
|
2023-08-16 23:48:56 +03:00
|
|
|
const json = poParser.parse(po)
|
2023-07-13 02:57:39 +03:00
|
|
|
return {
|
|
|
|
locale,
|
|
|
|
json,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default defineConfig((env) => {
|
|
|
|
return createLibConfig({
|
2023-08-09 22:27:35 +03:00
|
|
|
index: 'lib/index.ts',
|
2023-07-13 02:57:39 +03:00
|
|
|
}, {
|
|
|
|
inlineCSS: false,
|
2023-07-20 16:43:40 +03:00
|
|
|
config: {
|
|
|
|
build: {
|
|
|
|
// Fix for vite config, TODO: remove with next release
|
|
|
|
cssCodeSplit: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodeExternalsOptions: {
|
|
|
|
include: [/^@nextcloud\//],
|
|
|
|
},
|
2023-07-13 02:57:39 +03:00
|
|
|
libraryFormats: ['es', 'cjs'],
|
|
|
|
replace: {
|
2023-07-20 16:43:40 +03:00
|
|
|
__TRANSLATIONS__: JSON.stringify(translations),
|
2023-07-13 02:57:39 +03:00
|
|
|
},
|
|
|
|
DTSPluginOptions: {
|
|
|
|
rollupTypes: env.mode === 'production',
|
2023-07-20 16:43:40 +03:00
|
|
|
},
|
2023-07-13 02:57:39 +03:00
|
|
|
})(env)
|
2023-08-20 22:53:05 +03:00
|
|
|
}) as UserConfigFn
|