2024-04-30 20:44:26 +02:00
|
|
|
/// <reference types="vitest" />
|
2024-04-30 02:39:52 +02:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import autoprefixer from 'autoprefixer';
|
2024-04-30 12:16:09 +02:00
|
|
|
import postcssMixins from 'postcss-mixins';
|
|
|
|
import postcssSimpleVars from 'postcss-simple-vars';
|
|
|
|
import postcssRelativeColor from '@csstools/postcss-relative-color-syntax';
|
2024-04-30 02:39:52 +02:00
|
|
|
import { defineConfig, UserConfig, ConfigEnv } from 'vite';
|
|
|
|
|
2024-04-30 20:44:26 +02:00
|
|
|
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
|
|
|
|
const isDev = command !== 'build' && mode !== 'test';
|
2024-04-30 20:38:28 +02:00
|
|
|
const targets = new Map();
|
2024-04-30 02:39:52 +02:00
|
|
|
|
2024-04-30 20:38:28 +02:00
|
|
|
fs.readdirSync(path.resolve(__dirname, 'css/themes/')).forEach(name => {
|
|
|
|
const m = name.match(/([-a-z]+).css/);
|
2024-04-30 02:39:52 +02:00
|
|
|
|
2024-04-30 20:38:28 +02:00
|
|
|
if (m)
|
|
|
|
targets.set(`css/${m[1]}`, `./css/themes/${m[1]}.css`);
|
|
|
|
});
|
2024-04-30 02:39:52 +02:00
|
|
|
|
2024-04-30 20:38:28 +02:00
|
|
|
fs.readdirSync(path.resolve(__dirname, 'css/options/')).forEach(name => {
|
|
|
|
const m = name.match(/([-a-z]+).css/);
|
2024-04-30 02:39:52 +02:00
|
|
|
|
2024-04-30 20:38:28 +02:00
|
|
|
if (m)
|
|
|
|
targets.set(`css/options/${m[1]}`, `./css/options/${m[1]}.css`);
|
|
|
|
});
|
2024-04-30 02:39:52 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
publicDir: 'static',
|
|
|
|
plugins: [],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
common: path.resolve(__dirname, 'css/common/'),
|
2024-04-30 09:17:43 +02:00
|
|
|
views: path.resolve(__dirname, 'css/views/'),
|
|
|
|
elements: path.resolve(__dirname, 'css/elements/'),
|
|
|
|
themes: path.resolve(__dirname, 'css/themes/')
|
2024-04-30 02:39:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
build: {
|
2024-05-06 17:16:15 +02:00
|
|
|
target: ['es2016', 'chrome67', 'firefox62', 'edge18', 'safari12'],
|
2024-04-30 02:39:52 +02:00
|
|
|
outDir: path.resolve(__dirname, '../priv/static'),
|
|
|
|
emptyOutDir: false,
|
|
|
|
sourcemap: isDev,
|
|
|
|
manifest: false,
|
|
|
|
cssCodeSplit: true,
|
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
2024-06-06 18:48:16 +02:00
|
|
|
'js/app': './js/app.ts',
|
2024-04-30 12:16:09 +02:00
|
|
|
'css/application': './css/application.css',
|
2024-04-30 20:38:28 +02:00
|
|
|
...Object.fromEntries(targets)
|
2024-04-30 02:39:52 +02:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
entryFileNames: '[name].js',
|
|
|
|
chunkFileNames: '[name].js',
|
|
|
|
assetFileNames: '[name][extname]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
postcss: {
|
2024-04-30 20:38:28 +02:00
|
|
|
plugins: [postcssMixins(), postcssSimpleVars(), postcssRelativeColor(), autoprefixer]
|
2024-04-30 02:39:52 +02:00
|
|
|
}
|
2024-04-30 20:44:26 +02:00
|
|
|
},
|
|
|
|
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}'],
|
|
|
|
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-04-30 02:39:52 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|