-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.js
82 lines (80 loc) · 2.37 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
import { readFileSync } from 'node:fs';
import { cpus } from 'node:os';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import { externalizeDeps } from 'vite-plugin-externalize-deps';
/**
* Resolves the path to the given file.
* @param {string} str
* @returns {string}
*/
const resolvePath = str => resolve(new URL(import.meta.url).pathname.replace('/vite.config.js', ''), str);
const outputDir = process.env.BUILD_ENV === 'production' ? 'dist' : 'dist-temp';
const globalConfig = {
pkg: JSON.parse(readFileSync(resolvePath('package.json'), 'utf-8')),
};
export default defineConfig({
plugins: [
externalizeDeps({
deps: true,
devDeps: true,
except: [],
nodeBuiltins: true,
optionalDeps: true,
peerDeps: true,
useFile: resolvePath('package.json'),
}),
],
build: {
lib: {
name: 'vue-ray',
entry: ['src/index.ts'],
formats: ['es', 'cjs'],
fileName: format => {
if (format === 'es') return 'index.js';
return 'index.cjs';
},
},
outDir: outputDir,
rollupOptions: {
treeshake: true,
},
},
server: {
watch: {
usePolling: true,
ignored: ['**/node_modules/**', '**/dist/**', './coverage/**', '**/.git/**'],
},
},
cacheDir: resolvePath('.cache'),
resolve: {
alias: {
'@': resolvePath('./src'),
},
},
define: {
__BUILD_VERSION__: JSON.stringify(globalConfig.pkg.version),
__LIBRARY_NAME__: JSON.stringify(globalConfig.pkg.name),
},
test: {
name: 'VueRay',
globals: true,
passWithNoTests: true,
maxConcurrency: cpus().length - 1,
watch: false,
alias: {
'@/': new URL('./src/', import.meta.url).pathname,
},
coverage: {
processingConcurrency: cpus().length - 1,
thresholds: {
autoUpdate: true,
},
all: true,
include: ['src/**/*.ts', 'src/**/*.js'],
reporter: [['text'], ['json', { file: 'coverage.json' }]],
},
include: ['tests/**/*.ts', 'tests/**/*.js'],
reporters: ['default', process.env.CI ? 'github-actions' : 'verbose'],
},
});