shrub/pkg/grid/vite.config.ts

53 lines
1.5 KiB
TypeScript
Raw Normal View History

import { loadEnv, defineConfig } from 'vite';
import analyze from 'rollup-plugin-analyzer';
import { visualizer } from 'rollup-plugin-visualizer';
import reactRefresh from '@vitejs/plugin-react-refresh';
2021-08-26 03:14:48 +03:00
import htmlPlugin from 'vite-plugin-html-config';
2021-09-20 22:54:50 +03:00
import { execSync } from 'child_process';
2021-08-26 03:14:48 +03:00
const htmlPluginOpt = {
headScripts: [{ src: '/apps/grid/desk.js' }, { src: '/session.js' }]
};
2021-09-20 22:54:50 +03:00
const GIT_DESC = execSync('git describe --always', { encoding: 'utf8' }).trim();
process.env.VITE_SHORTHASH = GIT_DESC;
// https://vitejs.dev/config/
export default ({ mode }) => {
Object.assign(process.env, loadEnv(mode, process.cwd()));
const SHIP_URL = process.env.SHIP_URL || process.env.VITE_SHIP_URL || 'http://localhost:8080';
console.log(SHIP_URL);
return defineConfig({
base: mode === 'mock' ? undefined : '/apps/grid/',
server:
mode === 'mock'
? undefined
: {
2021-09-17 03:45:06 +03:00
https: true,
proxy: {
'^/apps/grid/desk.js': {
target: SHIP_URL
},
'^((?!/apps/grid).)*$': {
target: SHIP_URL
}
}
},
build:
mode !== 'profile'
? undefined
: {
rollupOptions: {
plugins: [
analyze({
limit: 20
}),
visualizer()
]
}
},
plugins: [htmlPlugin(htmlPluginOpt), reactRefresh()]
});
};