philomena/assets/vite.config.ts

88 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

/// <reference types="vitest" />
import fs from 'fs';
import path from 'path';
import autoprefixer from 'autoprefixer';
import { defineConfig, UserConfig, ConfigEnv } from 'vite';
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
const isDev = command !== 'build' && mode !== 'test';
2024-07-04 02:27:59 +02:00
const themeNames = fs.readdirSync(path.resolve(__dirname, 'css/themes/')).map(name => {
const m = name.match(/([-a-z]+).scss/);
2024-07-04 02:27:59 +02:00
if (m) {
return m[1];
}
return null;
});
const themes = new Map();
for (const name of themeNames) {
themes.set(`css/${name}`, `./css/themes/${name}.scss`);
}
return {
publicDir: 'static',
plugins: [],
2024-06-10 21:17:06 +02:00
server: {
host: '0.0.0.0',
port: 5173,
},
resolve: {
alias: {
common: path.resolve(__dirname, 'css/common/'),
2024-07-04 02:27:59 +02:00
views: path.resolve(__dirname, 'css/views/'),
},
},
build: {
2024-05-06 17:16:15 +02:00
target: ['es2016', 'chrome67', 'firefox62', 'edge18', 'safari12'],
outDir: path.resolve(__dirname, '../priv/static'),
emptyOutDir: false,
sourcemap: isDev,
manifest: false,
cssCodeSplit: true,
rollupOptions: {
input: {
2024-06-09 22:30:21 +02:00
'js/app': './js/app.ts',
2024-07-04 02:27:59 +02:00
...Object.fromEntries(themes),
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
2024-07-04 02:27:59 +02:00
assetFileNames: '[name][extname]',
},
},
},
css: {
2024-07-04 02:27:59 +02:00
postcss: {
plugins: [autoprefixer],
},
},
test: {
globals: true,
environment: 'jsdom',
// TODO Jest --randomize CLI flag equivalent, consider enabling in the future
// sequence: { shuffle: true },
setupFiles: './test/vitest-setup.ts',
coverage: {
reporter: ['text', 'html'],
include: ['js/**/*.{js,ts}'],
2024-07-04 02:27:59 +02:00
exclude: ['node_modules/', '.*\\.test\\.ts$', '.*\\.d\\.ts$'],
thresholds: {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
'**/utils/**/*.ts': {
statements: 100,
branches: 100,
functions: 100,
lines: 100,
},
2024-07-04 02:27:59 +02:00
},
},
},
};
});