// @ts-check // `resolveJsonModule` is disabled for this package, but vite will load the json nevertheless. // @ts-expect-error import { chrome as chromeVersion, node as nodeVersion } from '../.electron-vendors.cache.json'; /** @type {string} */ const banner = `/*! * Copyright (C) 2021-2022 Sophie contributors * * This file is part of Sophie. * * Sophie is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * * SPDX-License-Identifier: AGPL-3.0-only */ `; /** @type {string} */ export const chrome = `chrome${chromeVersion}`; /** @type {string} */ export const node = `node${nodeVersion}`; /** * Extends a vite configuration with common options. * * @param {import('vite').UserConfig} config The configuration to extend. * @return {import('vite').UserConfig} The configuration extended with common options. */ export function makeConfig(config) { return { mode: process.env.NODE, envDir: process.cwd(), ...config, build: { assetsDir: '.', outDir: 'dist', emptyOutDir: true, sourcemap: true, minify: process.env.MODE !== 'development', brotliSize: false, ...config.build, lib: (typeof config.build.lib === 'object') ? { fileName: (format) => format === 'cjs' ? 'index.cjs' : `index.${format}.js`, ...config.build.lib, } : undefined, rollupOptions: { ...config.build?.rollupOptions, output: { banner, ...config.build?.rollupOptions?.output, }, }, }, }; }