55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import { defineConfig } from 'vite';
|
|
import { copyFileSync, cpSync } from 'node:fs';
|
|
import { extname, relative, resolve } from 'node:path';
|
|
|
|
function reloadFinancialData() {
|
|
return {
|
|
name: 'reload-financial-data',
|
|
configureServer(server) {
|
|
server.watcher.add(['manifest.json', 'data/**/*.csv']);
|
|
server.watcher.on('change', (file) => {
|
|
if (file.endsWith('.csv') || file.endsWith('/manifest.json')) {
|
|
server.ws.send({ type: 'full-reload', path: '*' });
|
|
}
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
function copyRuntimeData() {
|
|
let outputDirectory;
|
|
const dataDirectory = resolve('data');
|
|
|
|
return {
|
|
name: 'copy-runtime-data',
|
|
apply: 'build',
|
|
configResolved(config) {
|
|
outputDirectory = resolve(config.build.outDir);
|
|
},
|
|
closeBundle() {
|
|
copyFileSync('manifest.json', resolve(outputDirectory, 'manifest.json'));
|
|
cpSync(dataDirectory, resolve(outputDirectory, 'data'), {
|
|
recursive: true,
|
|
filter: (source) => {
|
|
const path = relative(dataDirectory, source);
|
|
return path === '' || extname(path) === '' || path.endsWith('.csv');
|
|
},
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
server: {
|
|
host: '127.0.0.1',
|
|
port: 8899,
|
|
strictPort: true,
|
|
},
|
|
preview: {
|
|
host: '127.0.0.1',
|
|
port: 8899,
|
|
strictPort: true,
|
|
},
|
|
plugins: [reloadFinancialData(), copyRuntimeData()],
|
|
});
|