2024-05-28 17:24:06 +03:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: CC0-1.0
|
|
|
|
*/
|
|
|
|
|
2023-06-21 07:08:48 +03:00
|
|
|
import type { Plugin } from 'vite'
|
2023-07-28 11:54:12 +03:00
|
|
|
import { createLibConfig } from '@nextcloud/vite-config'
|
2023-08-02 01:39:56 +03:00
|
|
|
import { globSync } from 'glob'
|
|
|
|
import { join, resolve } from 'node:path'
|
2023-06-21 07:08:48 +03:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
|
|
import md5 from 'md5'
|
|
|
|
import * as url from 'url'
|
|
|
|
|
2023-11-21 16:46:48 +03:00
|
|
|
import l10nPlugin from './build/l10n-plugin.mts'
|
2023-06-21 07:08:48 +03:00
|
|
|
|
|
|
|
// `__dirname` not available on ES modules by default
|
|
|
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
|
|
|
|
|
|
|
const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-vue')
|
2024-02-29 14:06:10 +03:00
|
|
|
const versionHash = md5(appVersion).slice(0, 7) as string
|
|
|
|
const SCOPE_VERSION = JSON.stringify(versionHash)
|
2023-06-21 07:08:48 +03:00
|
|
|
|
|
|
|
// Entry points which we build using vite
|
|
|
|
const entryPoints = {
|
2024-05-06 17:43:10 +03:00
|
|
|
...globSync(['src/components/*/index.js', 'src/components/*/index.ts']).reduce((acc, item) => {
|
2023-08-02 01:39:56 +03:00
|
|
|
const name = item
|
2024-05-06 17:43:10 +03:00
|
|
|
.replace(/\/index\.[jt]s/, '')
|
2023-08-02 01:39:56 +03:00
|
|
|
.replace('src/components/', 'Components/')
|
|
|
|
acc[name] = join(__dirname, item)
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
2024-05-06 17:43:10 +03:00
|
|
|
...globSync(['src/directives/*/index.js', 'src/directives/*/index.ts']).reduce((acc, item) => {
|
2023-08-02 01:39:56 +03:00
|
|
|
const name = item
|
2024-05-06 17:43:10 +03:00
|
|
|
.replace(/\/index\.[jt]s/, '')
|
2023-08-02 01:39:56 +03:00
|
|
|
.replace('src/directives/', 'Directives/')
|
|
|
|
acc[name] = join(__dirname, item)
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
2024-05-06 17:43:10 +03:00
|
|
|
...globSync(['src/functions/*/index.js', 'src/functions/*/index.ts']).reduce((acc, item) => {
|
2023-08-02 01:39:56 +03:00
|
|
|
const name = item
|
2024-05-06 17:43:10 +03:00
|
|
|
.replace(/\/index\.[jt]s/, '')
|
2023-08-02 01:39:56 +03:00
|
|
|
.replace('src/functions/', 'Functions/')
|
|
|
|
acc[name] = join(__dirname, item)
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
2024-05-06 17:43:10 +03:00
|
|
|
...globSync(['src/mixins/*/index.js', 'src/mixins/*/index.ts']).reduce((acc, item) => {
|
2023-08-02 01:39:56 +03:00
|
|
|
const name = item
|
2024-05-06 17:43:10 +03:00
|
|
|
.replace(/\/index\.[jt]s/, '')
|
2023-08-02 01:39:56 +03:00
|
|
|
.replace('src/mixins/', 'Mixins/')
|
|
|
|
acc[name] = join(__dirname, item)
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
2024-04-12 22:15:54 +03:00
|
|
|
...globSync(['src/composables/*/index.js', 'src/composables/*/index.ts']).reduce((acc, item) => {
|
2023-11-06 18:15:13 +03:00
|
|
|
const name = item
|
2024-04-12 22:15:54 +03:00
|
|
|
.replace(/\/index\.[jt]s/, '')
|
2023-11-06 18:15:13 +03:00
|
|
|
.replace('src/composables/', 'Composables/')
|
|
|
|
acc[name] = join(__dirname, item)
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
2023-06-21 07:08:48 +03:00
|
|
|
index: resolve(__dirname, 'src/index.js'),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plugin for stripping out <docs> sections from vue files
|
|
|
|
const vueDocsPlugin: Plugin = {
|
|
|
|
name: 'vue-docs-plugin',
|
|
|
|
transform(code, id) {
|
|
|
|
if (!/vue&type=doc/.test(id)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return 'export default ""'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Customizations for the vite config
|
|
|
|
const overrides = defineConfig({
|
|
|
|
plugins: [
|
|
|
|
vueDocsPlugin,
|
2023-11-21 16:46:48 +03:00
|
|
|
l10nPlugin(resolve(__dirname, 'l10n')),
|
2023-06-21 07:08:48 +03:00
|
|
|
],
|
|
|
|
css: {
|
|
|
|
devSourcemap: true,
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
|
|
|
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
|
|
|
|
sourceMapContents: false,
|
|
|
|
includePaths: [
|
|
|
|
resolve(__dirname, 'src/assets'),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// We need a callback config so we can access the vite build mode
|
|
|
|
export default defineConfig((env) => {
|
|
|
|
|
|
|
|
const createConfig = createLibConfig(entryPoints, {
|
|
|
|
// Add our overrides to the config
|
|
|
|
config: overrides,
|
2023-11-08 14:21:07 +03:00
|
|
|
// By default all dependencies are external, but no path imports
|
2023-06-21 07:08:48 +03:00
|
|
|
nodeExternalsOptions: {
|
2023-11-08 14:21:07 +03:00
|
|
|
// Packages with paths imports should be added here to mark them as external as well
|
|
|
|
include: [/^@nextcloud\/.+\//, /^@mdi\/svg\//],
|
|
|
|
// Make sure to not provide uncompiled vue files as dependencies, this will break unit tests
|
|
|
|
exclude: [/\.vue(\?|$)/],
|
2023-06-21 07:08:48 +03:00
|
|
|
},
|
|
|
|
// For backwards compatibility we include the css within the js files
|
|
|
|
inlineCSS: true,
|
2023-07-12 17:04:55 +03:00
|
|
|
// Build CommonJS files for backwards compatibility
|
|
|
|
libraryFormats: ['es', 'cjs'],
|
2023-06-21 07:08:48 +03:00
|
|
|
replace: {
|
|
|
|
PRODUCTION: JSON.stringify(env.mode === 'production'),
|
2024-02-29 16:40:58 +03:00
|
|
|
SCOPE_VERSION,
|
2023-06-21 07:08:48 +03:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return createConfig(env)
|
|
|
|
})
|