2024-06-12 20:47:09 +03:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: CC0-1.0
|
|
|
|
*/
|
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-10-17 14:34:11 +03:00
|
|
|
filepicker: 'lib/filepicker.ts',
|
2023-07-13 02:57:39 +03:00
|
|
|
}, {
|
2023-07-20 16:43:40 +03:00
|
|
|
config: {
|
|
|
|
build: {
|
|
|
|
// Fix for vite config, TODO: remove with next release
|
|
|
|
cssCodeSplit: false,
|
|
|
|
},
|
|
|
|
},
|
2023-10-17 14:30:51 +03:00
|
|
|
// We build for ESM and legacy common js
|
|
|
|
libraryFormats: ['es', 'cjs'],
|
|
|
|
// We want one single output CSS file
|
|
|
|
inlineCSS: false,
|
|
|
|
// Packages that should be externalized or bundled
|
2023-07-20 16:43:40 +03:00
|
|
|
nodeExternalsOptions: {
|
2023-08-27 03:07:43 +03:00
|
|
|
// for subpath imports like '@nextcloud/l10n/gettext'
|
2023-07-20 16:43:40 +03:00
|
|
|
include: [/^@nextcloud\//],
|
2023-11-25 14:51:47 +03:00
|
|
|
exclude: [
|
2024-01-17 20:22:04 +03:00
|
|
|
// we should not rely on external vue SFC dependencies thus bundle all .vue files
|
|
|
|
/^vue-material-design-icons\//,
|
|
|
|
/\.vue(\?|$)/,
|
2023-11-25 14:51:47 +03:00
|
|
|
// and bundle raw data, e.g., raw SVGs
|
2024-01-17 20:22:04 +03:00
|
|
|
/\?raw$/,
|
2023-11-25 14:51:47 +03:00
|
|
|
],
|
2023-07-20 16:43:40 +03:00
|
|
|
},
|
2023-10-17 14:30:51 +03:00
|
|
|
// Inject our translations
|
2023-07-13 02:57:39 +03:00
|
|
|
replace: {
|
2023-07-20 16:43:40 +03:00
|
|
|
__TRANSLATIONS__: JSON.stringify(translations),
|
2023-07-13 02:57:39 +03:00
|
|
|
},
|
2023-10-17 14:30:51 +03:00
|
|
|
// Rollup our type definitions to only publish what it needed
|
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
|