-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
125 lines (112 loc) · 3.58 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import path from 'path';
import fs from 'fs';
import { ConfigEnv, defineConfig, UserConfigExport } from 'vitest/config';
import react from '@vitejs/plugin-react';
import eslintPlugin from 'vite-plugin-eslint';
import StylelintPlugin from 'vite-plugin-stylelint';
import { VitePWA } from 'vite-plugin-pwa';
import { createHtmlPlugin } from 'vite-plugin-html';
import { Target, viteStaticCopy } from 'vite-plugin-static-copy';
export default ({ mode, command }: ConfigEnv): UserConfigExport => {
// Shorten default mode names to dev / prod
// Also differentiates from build type (production / development)
mode = mode === 'development' ? 'dev' : mode;
mode = mode === 'production' ? 'prod' : mode;
const localFile = `ini/.webapp.${mode}.ini`;
const templateFile = `ini/templates/.webapp.${mode}.ini`;
// The build ONLY uses .ini files in /ini to include in the build output.
// All .ini files in the directory are git ignored to customer specific values out of source control.
// However, this script will automatically create a .ini file for the current mode if it doesn't exist
// by copying the corresponding mode file from the ini/templates directory.
if (!fs.existsSync(localFile) && fs.existsSync(templateFile)) {
fs.copyFileSync(templateFile, localFile);
}
// Make sure to builds are always production type,
// otherwise modes other than 'production' get built in dev
if (command === 'build') {
process.env.NODE_ENV = 'production';
}
const plugins = [
react(),
eslintPlugin({ emitError: mode === 'production' || mode === 'demo' }), // Move linting to pre-build to match dashboard
StylelintPlugin(),
VitePWA(),
createHtmlPlugin({
minify: true,
}),
];
const fileCopyTargets: Target[] = [
{
src: localFile,
dest: '',
rename: '.webapp.ini',
},
];
// These files are only needed in dev / test / demo, so don't include in prod builds
if (mode !== 'prod') {
fileCopyTargets.push({
src: 'test/epg/*',
dest: 'epg',
});
}
plugins.push(
viteStaticCopy({
targets: fileCopyTargets,
}),
);
return defineConfig({
plugins: plugins,
publicDir: './public',
envPrefix: 'APP_',
server: {
port: 8080,
},
mode: mode,
build: {
outDir: './build/public',
cssCodeSplit: false,
minify: true,
rollupOptions: {
output: {
manualChunks: (id) => {
// I originally just wanted to separate react-dom as its own bundle,
// but you get an error at runtime without these dependencies
if (
id.includes('/node_modules/react-dom/') ||
id.includes('/node_modules/scheduler/') ||
id.includes('/node_modules/object-assign/') ||
id.includes('/node_modules/react/')
) {
return 'react';
}
if (id.includes('/node_modules/@inplayer')) {
return 'inplayer';
}
if (id.includes('/node_modules/')) {
return 'vendor';
}
return 'index';
},
},
},
},
css: {
devSourcemap: true,
},
resolve: {
alias: {
'#src': path.join(__dirname, 'src'),
'#components': path.join(__dirname, 'src/components'),
'#test': path.join(__dirname, 'test'),
'#test-e2e': path.join(__dirname, 'test-e2e'),
'#types': path.join(__dirname, 'types'),
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['test/vitest.setup.ts'],
css: true,
},
});
};