2024-11-18 14:12:33 +03:00
|
|
|
import path from 'path';
|
2023-11-08 15:33:18 +03:00
|
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
import glob from 'glob';
|
|
|
|
import {resolve} from 'path';
|
|
|
|
import svgr from 'vite-plugin-svgr';
|
|
|
|
import {defineConfig} from 'vitest/config';
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
export default (function viteConfig() {
|
|
|
|
return defineConfig({
|
2023-11-15 11:51:52 +03:00
|
|
|
logLevel: process.env.CI ? 'info' : 'warn',
|
2023-11-08 15:33:18 +03:00
|
|
|
plugins: [
|
|
|
|
svgr(),
|
|
|
|
react()
|
|
|
|
],
|
2024-11-18 14:12:33 +03:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': path.resolve(__dirname, './src')
|
|
|
|
}
|
|
|
|
},
|
2023-11-08 15:33:18 +03:00
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
|
|
'process.env.VITEST_SEGFAULT_RETRY': 3
|
|
|
|
},
|
|
|
|
preview: {
|
|
|
|
port: 4174
|
|
|
|
},
|
|
|
|
build: {
|
2023-11-15 11:04:18 +03:00
|
|
|
reportCompressedSize: false,
|
2023-11-08 15:33:18 +03:00
|
|
|
minify: false,
|
|
|
|
sourcemap: true,
|
|
|
|
outDir: 'es',
|
|
|
|
lib: {
|
|
|
|
formats: ['es'],
|
2024-11-18 14:12:33 +03:00
|
|
|
entry: glob.sync(resolve(__dirname, 'src/**/*.{ts,tsx}')).reduce((entries, libpath) => {
|
|
|
|
if (libpath.includes('.stories.') || libpath.endsWith('.d.ts')) {
|
2023-11-08 15:33:18 +03:00
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2024-11-18 14:12:33 +03:00
|
|
|
const outPath = libpath.replace(resolve(__dirname, 'src') + '/', '').replace(/\.(ts|tsx)$/, '');
|
|
|
|
entries[outPath] = libpath;
|
2023-11-08 15:33:18 +03:00
|
|
|
return entries;
|
|
|
|
}, {} as Record<string, string>)
|
|
|
|
},
|
|
|
|
commonjsOptions: {
|
|
|
|
include: [/packages/, /node_modules/]
|
|
|
|
},
|
|
|
|
rollupOptions: {
|
|
|
|
external: (source) => {
|
|
|
|
if (source.startsWith('.')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source.includes('node_modules')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !source.includes(__dirname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
test: {
|
|
|
|
globals: true, // required for @testing-library/jest-dom extensions
|
|
|
|
environment: 'jsdom',
|
|
|
|
include: ['./test/unit/**/*'],
|
|
|
|
testTimeout: process.env.TIMEOUT ? parseInt(process.env.TIMEOUT) : 10000,
|
|
|
|
...(process.env.CI && { // https://github.com/vitest-dev/vitest/issues/1674
|
|
|
|
minThreads: 1,
|
|
|
|
maxThreads: 2
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|