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 postcssNested from 'postcss-nested';
|
|
|
|
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';
|
|
|
|
|
|
|
|
export default defineConfig(({ command }: ConfigEnv): UserConfig => {
|
|
|
|
const isDev = command !== 'build';
|
|
|
|
|
|
|
|
if (isDev) {
|
|
|
|
process.stdin.on('close', () => {
|
|
|
|
// eslint-disable-next-line no-process-exit
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.stdin.resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
const themeNames =
|
|
|
|
fs.readdirSync(path.resolve(__dirname, 'css/themes/')).map(name => {
|
2024-04-30 12:16:09 +02:00
|
|
|
const m = name.match(/([-a-z]+).css/);
|
2024-04-30 02:39:52 +02:00
|
|
|
|
|
|
|
if (m) { return m[1]; }
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const themes = new Map();
|
|
|
|
|
|
|
|
for (const name of themeNames) {
|
2024-04-30 12:16:09 +02:00
|
|
|
themes.set(`css/${name}`, `./css/themes/${name}.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: {
|
|
|
|
target: 'es2020',
|
|
|
|
outDir: path.resolve(__dirname, '../priv/static'),
|
|
|
|
emptyOutDir: false,
|
|
|
|
sourcemap: isDev,
|
|
|
|
manifest: false,
|
|
|
|
cssCodeSplit: true,
|
|
|
|
rollupOptions: {
|
|
|
|
input: {
|
|
|
|
'js/app': './js/app.js',
|
2024-04-30 12:16:09 +02:00
|
|
|
'css/application': './css/application.css',
|
2024-04-30 02:39:52 +02:00
|
|
|
...Object.fromEntries(themes)
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
entryFileNames: '[name].js',
|
|
|
|
chunkFileNames: '[name].js',
|
|
|
|
assetFileNames: '[name][extname]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
postcss: {
|
2024-04-30 12:16:09 +02:00
|
|
|
plugins: [postcssMixins(), postcssNested(), postcssSimpleVars, postcssRelativeColor(), autoprefixer]
|
2024-04-30 02:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|