-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvite.config.ts
45 lines (39 loc) · 1.21 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*!
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*/
import * as fs from 'node:fs'
import { resolve } from 'node:path'
import { po as poParser } from 'gettext-parser'
import { createLibConfig } from '@nextcloud/vite-config'
const translations = fs
.readdirSync('./l10n')
.filter((name) => name !== 'messages.pot' && name.endsWith('.pot'))
.map((file) => {
const path = `./l10n/${file}`
const locale = file.slice(0, -'.pot'.length)
const po = fs.readFileSync(path)
const json = poParser.parse(po)
// Compress translations by removing everything not needed
const translations = Object.values(json.translations[''])
.filter((value) => value.msgid !== '')
.map((value) => ({
msgid: value.msgid,
msgid_plural: value.msgid_plural,
msgstr: value.msgstr,
}))
return { locale, translations }
})
export default createLibConfig({
index: resolve(__dirname, 'src/main.ts'),
}, {
libraryFormats: ['cjs', 'es'],
// Rename CSS chunk
assetFileNames: (chunkInfo) => chunkInfo.name?.endsWith('.css') ? 'style.css' : undefined,
replace: {
__TRANSLATIONS__: `;${JSON.stringify(translations)}`,
},
DTSPluginOptions: {
rollupTypes: true,
},
})