diff options
author | 2021-12-23 17:19:52 +0100 | |
---|---|---|
committer | 2021-12-23 17:54:03 +0100 | |
commit | a8c4df8744ac0d9e6a889af3ad3dcbd3e100ee0a (patch) | |
tree | d10c6ab5daa20f49594dfcc3b842dff4e963a670 /config/vite-common.js | |
parent | build: Enable typescript composite mode and clean (diff) | |
download | sophie-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/vite-common.js')
-rw-r--r-- | config/vite-common.js | 67 |
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 | ||
5 | import { chrome as chromeVersion, node as nodeVersion } from '../.electron-vendors.cache.json'; | ||
6 | |||
7 | /** @type string */ | ||
8 | const 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 */ | ||
30 | export const chrome = `chrome${chromeVersion}`; | ||
31 | |||
32 | /** @type string */ | ||
33 | export 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 | */ | ||
41 | export 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 | } | ||