Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Last active January 24, 2024 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/407e85bc48870216eace1a5b5791f05e to your computer and use it in GitHub Desktop.
Save kuc-arc-f/407e85bc48870216eace1a5b5791f05e to your computer and use it in GitHub Desktop.
vite.config.ts , react + vite, sample
VITE_API_KEY="123"
VITE_API_URL=http://localhost:4000
{
"name": "react18_11pages",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"deploy": "npx wrangler pages deploy dist",
"build": "tsc && vite build",
"build:prod": "tsc && vite build --mode production",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.0"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"postcss": "^8.4.32",
"tailwindcss": "^3.4.0",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
if (mode === 'production') {
return {
plugins: [react()],
define: {
"process.env.NODE_ENV": '"production"',
},
build: {
lib: {
entry: [
'./src/main.tsx',
],
formats: ['es'],
fileName: '[name]',
},
rollupOptions: {
output: {
dir: './dist/static'
}
},
emptyOutDir: false,
copyPublicDir: false
}
}
}else{
return {
plugins: [react()],
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment