-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvite.config.js
99 lines (96 loc) · 3.31 KB
/
vite.config.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/// <reference types="vitest" />
/** @type {import('vite').UserConfig} */
import { defineConfig } from 'vite';
import { fileURLToPath } from 'url';
import { dynamicBase } from 'vite-plugin-dynamic-base';
import { execSync } from "child_process";
import react from '@vitejs/plugin-react';
import svgrPlugin from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import commonjs from 'vite-plugin-commonjs';
import viteCompression from 'vite-plugin-compression';
import vitePluginCp from 'vite-plugin-cp';
import 'vite-compatible-readable-stream';
export default defineConfig(() => {
let commitHash = '', version = '';
if (process.env.VITEST !== 'true') {
try {
commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
version = execSync('git describe --tags --always').toString().trimEnd();
} catch (error) {
console.log('⛔️ describe may not getting the latest tag')
}
}
return ({
base: process.env.NODE_ENV === 'production' ? "/__BASE__/" : "/",
plugins: [
react(),
tsconfigPaths(),
svgrPlugin(),
commonjs(),
viteCompression(),
dynamicBase({
publicPath: 'window.__BASE__',
transformIndexHtml: true,
}),
vitePluginCp({
targets: [
{ src: 'public/', dest: 'dist/public' },
]
})
],
resolve: {
alias: {
process: 'process/browser',
buffer: 'buffer',
crypto: 'crypto-browserify',
stream: 'stream-browserify',
path: 'path-browserify',
assert: 'assert',
http: 'stream-http',
https: 'https-browserify',
os: 'os-browserify',
url: 'url',
util: 'util'
}
},
define: {
'process.env': process.env,
FUSION_VERSION: process.env.NODE_ENV === 'test' ? JSON.stringify('1.0.0') : JSON.stringify(version),
COMMIT_HASH: JSON.stringify(commitHash),
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: ["./vitest-setup.js"],
testTimeout: 60000,
reporters: process.env.REPORT === 'true',
sequence: {
shuffle: true,
},
},
build: {
minify: true,
cssMinify: true,
manifest: true,
emptyOutDir: false,
outDir: 'dist',
assetsDir: 'public',
sourcemap: process.env.NODE_ENV !== 'production',
commonjsOptions: {
transformMixedEsModules: true
},
rollupOptions: {
input: fileURLToPath(new URL('./index.html', import.meta.url)),
output: {
manualChunks: {
lodash: ['lodash'],
pdfjs: ['node_modules/pdfjs-dist/build/pdf.worker.min.mjs'],
codemirror: ["codemirror", "react-codemirror2"]
}
}
}
},
assetsInclude: ['**/*.jpg', '**/*.jpeg', '**/*.mp4', '**/*.png', '**/*.svg']
})
});