Files
qwerty-learner/vite.config.ts
2023-04-17 17:35:20 +08:00

37 lines
1.2 KiB
TypeScript

import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig, type PluginOption } from 'vite'
import react from '@vitejs/plugin-react'
import jotaiDebugLabel from 'jotai/babel/plugin-debug-label'
import jotaiReactRefresh from 'jotai/babel/plugin-react-refresh'
import path from 'node:path'
import { getLastCommit } from 'git-last-commit'
// https://vitejs.dev/config/
export default defineConfig(async () => {
const latestCommitHash = await new Promise<string>((resolve) => {
return getLastCommit((err, commit) => (err ? 'unknown' : resolve(commit.shortHash)))
})
return {
plugins: [react({ babel: { plugins: [jotaiDebugLabel, jotaiReactRefresh] } }), visualizer() as PluginOption],
build: {
minify: true,
outDir: 'build',
sourcemap: true,
},
define: {
REACT_APP_DEPLOY_ENV: JSON.stringify(process.env.REACT_APP_DEPLOY_ENV),
LATEST_COMMIT_HASH: JSON.stringify(latestCommitHash + (process.env.NODE_ENV === 'production' ? '' : ' (dev)')),
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
},
}
})