-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
84 lines (80 loc) · 2.05 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import react from '@vitejs/plugin-react'
import * as path from 'node:path'
import { defineConfig, splitVendorChunkPlugin } from 'vite'
import { VitePWA as vitePwaPlugin } from 'vite-plugin-pwa'
const PRODUCTION = 'production'
const DEVELOPMENT = 'development'
const environment =
process.env.NODE_ENV === PRODUCTION ? PRODUCTION : DEVELOPMENT
const is_production = environment === PRODUCTION
const root = `${process.cwd()}/src`
const dist = `${process.cwd()}/dist`
export default defineConfig({
build: {
assetsDir: 'assets',
chunkSizeWarningLimit: 500,
emptyOutDir: true,
minify: is_production ? 'terser' : undefined,
outDir: dist,
rollupOptions: {
input: {
index: `${path.resolve(root, 'index.html')}/`,
},
output: {
assetFileNames: is_production
? 'assets/[hash][extname]'
: 'assets/[name]-[hash][extname]',
chunkFileNames: is_production
? 'assets/[hash].js'
: 'assets/[name]-[hash].js',
entryFileNames: 'assets/[name].[hash].js',
manualChunks: {
vendor: ['react', 'react-dom'],
emotion: ['@emotion/react', '@emotion/styled', 'twin.macro'],
},
},
},
terserOptions: is_production
? {
compress: {
drop_console: true,
},
}
: undefined,
},
plugins: [
react({
babel: {
plugins: [
'babel-plugin-macros',
[
'@emotion/babel-plugin-jsx-pragmatic',
{
export: 'jsx',
import: '__cssprop',
module: '@emotion/react',
},
],
[
'@babel/plugin-transform-react-jsx',
{ pragma: '__cssprop' },
'twin.macro',
],
],
},
}),
vitePwaPlugin({
registerType: 'autoUpdate',
workbox: {
inlineWorkboxRuntime: true,
},
}),
splitVendorChunkPlugin(),
],
root,
envDir: process.cwd(),
publicDir: `${process.cwd()}/public`,
server: {
port: 3000,
},
})