um-react/vite.config.ts

73 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2023-05-14 23:22:23 +00:00
import cp from 'node:child_process';
import url from 'node:url';
import path from 'node:path';
import fs from 'node:fs';
2023-05-09 00:22:00 +00:00
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import wasm from 'vite-plugin-wasm';
2023-05-14 23:22:23 +00:00
import replace from '@rollup/plugin-replace';
import topLevelAwait from 'vite-plugin-top-level-await';
2023-05-07 19:11:16 +00:00
2023-05-14 23:22:23 +00:00
const gitRoot = url.fileURLToPath(new URL('.', import.meta.url));
const pkg = JSON.parse(fs.readFileSync(gitRoot + '/package.json', 'utf-8'));
function command(cmd, dir = '') {
return cp.execSync(cmd, { cwd: path.join(gitRoot, dir), encoding: 'utf-8' }).trim();
}
const COMMAND_GIT_VERSION = 'git describe --long --dirty --tags --always';
const shortCommit = command(COMMAND_GIT_VERSION);
const version = `${pkg.version}-${shortCommit}`;
2023-05-07 19:11:16 +00:00
// https://vitejs.dev/config/
export default defineConfig({
server: {
fs: {
// Note:
// This is _insecure_, but is required to get pnpm link to work.
// strict: false,
allow: [
'src',
'node_modules',
// Allow pnpm to link.
'../libparakeet-js',
],
},
},
base: './',
optimizeDeps: {
exclude: ['@jixun/libparakeet'],
},
2023-05-14 23:22:23 +00:00
plugins: [
replace({
preventAssignment: true,
values: {
__APP_VERSION_SHORT__: pkg.version,
__APP_VERSION__: version,
},
}),
react(),
wasm(),
topLevelAwait(),
],
2023-05-09 00:22:00 +00:00
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
2023-05-15 20:39:58 +00:00
build: {
rollupOptions: {
output: {
manualChunks: {
reacts: ['react', 'react-dom', 'react-promise-suspense', 'react-redux', '@reduxjs/toolkit'],
chakra: ['@chakra-ui/icons', '@chakra-ui/react', '@emotion/react', '@emotion/styled', 'framer-motion'],
parakeet: ['@jixun/libparakeet'],
},
},
},
},
2023-05-09 00:22:00 +00:00
});