aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-23 17:19:52 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-23 17:54:03 +0100
commita8c4df8744ac0d9e6a889af3ad3dcbd3e100ee0a (patch)
treed10c6ab5daa20f49594dfcc3b842dff4e963a670 /config
parentbuild: Enable typescript composite mode and clean (diff)
downloadsophie-a8c4df8744ac0d9e6a889af3ad3dcbd3e100ee0a.tar.gz
sophie-a8c4df8744ac0d9e6a889af3ad3dcbd3e100ee0a.tar.zst
sophie-a8c4df8744ac0d9e6a889af3ad3dcbd3e100ee0a.zip
chore: Add license headers
Centralizes vite configuration to be able to add license banners to outputs in one place.
Diffstat (limited to 'config')
-rw-r--r--config/vite-common.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/config/vite-common.js b/config/vite-common.js
new file mode 100644
index 0000000..7d8e6a4
--- /dev/null
+++ b/config/vite-common.js
@@ -0,0 +1,67 @@
1// @ts-check
2
3// `resolveJsonModule` is disabled for this package, but vite will load the json nevertheless.
4// @ts-expect-error
5import { chrome as chromeVersion, node as nodeVersion } from '../.electron-vendors.cache.json';
6
7/** @type string */
8const banner = `/*!
9 * Copyright (C) 2021-2022 Sophie contributors
10 *
11 * This file is part of Sophie.
12 *
13 * Sophie is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Affero General Public License as
15 * published by the Free Software Foundation, version 3.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 *
25 * SPDX-License-Identifier: AGPL-3.0-only
26 */
27`;
28
29/** @type string */
30export const chrome = `chrome${chromeVersion}`;
31
32/** @type string */
33export const node = `node${nodeVersion}`;
34
35/**
36 * Extends a vite configuration with common options.
37 *
38 * @param config {import('vite').UserConfig} The configuration to extend.
39 * @return {import('vite').UserConfig} The configuration extended with common options.
40 */
41export function makeConfig(config) {
42 return {
43 mode: process.env.NODE,
44 envDir: process.cwd(),
45 ...config,
46 build: {
47 assetsDir: '.',
48 outDir: 'dist',
49 emptyOutDir: true,
50 sourcemap: true,
51 minify: process.env.MODE !== 'development',
52 brotliSize: false,
53 ...config.build,
54 lib: (typeof config.build.lib === 'object') ? {
55 fileName: (format) => format === 'cjs' ? 'index.cjs' : `index.${format}.js`,
56 ...config.build.lib,
57 } : undefined,
58 rollupOptions: {
59 ...config.build?.rollupOptions,
60 output: {
61 banner,
62 ...config.build?.rollupOptions?.output,
63 },
64 },
65 },
66 };
67}