mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-14 21:51:13 +00:00
Split vite & vitest configs, because vitest
is only in devDependencies
, so loading it from the config when yarn uses --production
fails the compilation
This commit is contained in:
parent
9dfb9d96be
commit
3d2ec6facd
|
@ -1,5 +1,3 @@
|
||||||
/// <reference types="vitest/config" />
|
|
||||||
|
|
||||||
import fs from 'node:fs/promises';
|
import fs from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
|
@ -11,12 +9,7 @@ import { analyzer } from 'vite-bundle-analyzer';
|
||||||
import RailsPlugin from 'vite-plugin-rails';
|
import RailsPlugin from 'vite-plugin-rails';
|
||||||
import { VitePWA } from 'vite-plugin-pwa';
|
import { VitePWA } from 'vite-plugin-pwa';
|
||||||
|
|
||||||
import {
|
import { defineConfig, UserConfigFnPromise, UserConfig } from 'vite';
|
||||||
configDefaults,
|
|
||||||
defineConfig,
|
|
||||||
ViteUserConfig,
|
|
||||||
UserConfigFnPromise,
|
|
||||||
} from 'vitest/config';
|
|
||||||
import postcssPresetEnv from 'postcss-preset-env';
|
import postcssPresetEnv from 'postcss-preset-env';
|
||||||
|
|
||||||
import { MastodonServiceWorkerLocales } from './config/vite/plugin-sw-locales';
|
import { MastodonServiceWorkerLocales } from './config/vite/plugin-sw-locales';
|
||||||
|
@ -24,7 +17,7 @@ import { MastodonServiceWorkerLocales } from './config/vite/plugin-sw-locales';
|
||||||
const jsRoot = path.resolve(__dirname, 'app/javascript');
|
const jsRoot = path.resolve(__dirname, 'app/javascript');
|
||||||
const entrypointRoot = path.resolve(jsRoot, 'entrypoints');
|
const entrypointRoot = path.resolve(jsRoot, 'entrypoints');
|
||||||
|
|
||||||
const config: UserConfigFnPromise = async ({ mode, command }) => {
|
export const config: UserConfigFnPromise = async ({ mode, command }) => {
|
||||||
const entrypointFiles = await fs.readdir(entrypointRoot);
|
const entrypointFiles = await fs.readdir(entrypointRoot);
|
||||||
const entrypoints: Record<string, string> = entrypointFiles.reduce(
|
const entrypoints: Record<string, string> = entrypointFiles.reduce(
|
||||||
(acc, file) => {
|
(acc, file) => {
|
||||||
|
@ -143,24 +136,7 @@ const config: UserConfigFnPromise = async ({ mode, command }) => {
|
||||||
optimizeLodashImports() as PluginOption,
|
optimizeLodashImports() as PluginOption,
|
||||||
!!process.env.ANALYZE_BUNDLE_SIZE && analyzer({ analyzerMode: 'static' }),
|
!!process.env.ANALYZE_BUNDLE_SIZE && analyzer({ analyzerMode: 'static' }),
|
||||||
],
|
],
|
||||||
test: {
|
} satisfies UserConfig;
|
||||||
environment: 'jsdom',
|
|
||||||
include: [
|
|
||||||
...configDefaults.include,
|
|
||||||
'**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
|
|
||||||
],
|
|
||||||
exclude: [
|
|
||||||
...configDefaults.exclude,
|
|
||||||
'**/node_modules/**',
|
|
||||||
'vendor/**',
|
|
||||||
'config/**',
|
|
||||||
'log/**',
|
|
||||||
'public/**',
|
|
||||||
'tmp/**',
|
|
||||||
],
|
|
||||||
globals: true,
|
|
||||||
},
|
|
||||||
} satisfies ViteUserConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineConfig(config);
|
export default defineConfig(config);
|
||||||
|
|
26
vitest.config.mts
Normal file
26
vitest.config.mts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { configDefaults, defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
import { config as viteConfig } from './vite.config.mjs';
|
||||||
|
|
||||||
|
export default defineConfig(async (context) => {
|
||||||
|
return {
|
||||||
|
...(await viteConfig(context)),
|
||||||
|
test: {
|
||||||
|
environment: 'jsdom',
|
||||||
|
include: [
|
||||||
|
...configDefaults.include,
|
||||||
|
'**/__tests__/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
|
||||||
|
],
|
||||||
|
exclude: [
|
||||||
|
...configDefaults.exclude,
|
||||||
|
'**/node_modules/**',
|
||||||
|
'vendor/**',
|
||||||
|
'config/**',
|
||||||
|
'log/**',
|
||||||
|
'public/**',
|
||||||
|
'tmp/**',
|
||||||
|
],
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user