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
|
|
|
// vitest configuration
|
|
|
|
test: {
|
|
|
|
environment: 'happy-dom',
|
|
|
|
coverage: {
|
|
|
|
all: true,
|
|
|
|
provider: 'v8',
|
|
|
|
include: ['lib/**/*.ts', 'lib/*.ts'],
|
|
|
|
exclude: ['lib/**/*.spec.ts'],
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
modules: {
|
|
|
|
classNameStrategy: 'non-scoped',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Fix unresolvable .css extension for ssr
|
|
|
|
server: {
|
|
|
|
deps: {
|
|
|
|
inline: [/@nextcloud\/vue/],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-07-20 16:43:40 +03:00
|
|
|
},
|
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-08-27 03:07:43 +03:00
|
|
|
// we should externalize vue SFC dependencies
|
|
|
|
exclude: [/^vue-material-design-icons\//, /\.vue(\?|$)/],
|
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
|