-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mts
173 lines (168 loc) · 4.1 KB
/
vite.config.mts
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { defineConfig, loadEnv } from 'vite';
import laravel from 'laravel-vite-plugin';
import { fileURLToPath } from 'url';
import { resolve } from 'path';
import richSvg from 'vite-plugin-react-rich-svg';
import manifestSRI from 'vite-plugin-manifest-sri';
import filterReplace from 'vite-plugin-filter-replace';
import react from '@vitejs/plugin-react';
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
import Info from 'unplugin-info/vite';
import { visualizer } from 'rollup-plugin-visualizer';
import laravelTranslations from 'vite-plugin-laravel-translations';
const ReactCompilerConfig = {};
const lottieScopeVariables = [
'value',
'content',
'loopOut',
'numKeys',
'$bm_mul',
'$bm_sum',
'$bm_sub',
'$bm_div',
'$bm_mod',
'$bm_isInstanceOfArray',
'$bm_transform',
'anchorPoint',
'time',
'velocity',
'inPoint',
'outPoint',
'width',
'height',
'name',
'loop_in',
'loop_out',
'smooth',
'toComp',
'fromCompToSurface',
'toWorld',
'fromWorld',
'mask',
'position',
'rotation',
'scale',
'thisComp',
'active',
'wiggle',
'loopInDuration',
'loopOutDuration',
'comp',
'lookAt',
'easeOut',
'easeIn',
'ease',
'nearestKey',
'key',
'text',
'textIndex',
'textTotal',
'selectorValue',
'framesToTime',
'timeToFrames',
'sourceRectAtTime',
'substring',
'substr',
'posterizeTime',
'index',
'globalData',
'frames',
'$bm_neg',
'add',
'clamp',
'radians_to_degrees',
'degreesToRadians',
'degrees_to_radians',
'normalize',
'rgbToHsl',
'hslToRgb',
'linear',
'random',
'createPath',
'_lottieGlobal',
'transform',
'effect',
'thisProperty',
'loopIn',
'fromComp',
'thisLayer',
'valueAtTime',
'velocityAtTime',
];
// https://vitejs.dev/config/
export default defineConfig(config => {
// Load env file based on `mode` in the current working directory.
// https://main.vitejs.dev/config/#using-environment-variables-in-config
const env = loadEnv(config.mode, process.cwd(), '');
return {
define: {
__APP_ENV__: JSON.stringify(env.APP_ENV),
},
build: {
sourcemap: false,
target: ['chrome128', 'firefox128', 'safari16', 'esnext'],
rollupOptions: {
treeshake: true,
},
},
plugins: [
laravel({
input: [
'resources/app/index.tsx',
],
refresh: true,
}),
react({
babel: {
plugins: [['babel-plugin-react-compiler', ReactCompilerConfig]],
},
}),
// @ts-ignore - wrongly typed
laravelTranslations.default({ namespace: 'translation' }),
visualizer({ open: false, template: 'flamegraph', filename: 'bundle-visualization.html' }),
optimizeCssModules(),
Info(),
richSvg(),
manifestSRI(),
// workaround for a warning with lottie https://github.com/airbnb/lottie-web/issues/2927
filterReplace([
{
filter: ['node_modules/lottie-web/build/player/lottie.js'],
replace: {
from: 'eval(\'[function _expression_function(){\' + val + \';scoped_bm_rt=$bm_rt}]\')[0]',
to: `
function _expression_function() {
var valToEval = val;
scoped_bm_rt = (new Function(
'valToEval', ${lottieScopeVariables.map((v) => `'${v}'`).join(',')},
'try {'
+ val + \`;
return $bm_rt;
} catch (e) {
console.error("Error in lottie-web workaround. Fix the issue in vite.config.ts:", e, "Failed expression:", valToEval);
throw e;
}\`
))(valToEval, ${lottieScopeVariables.join(',')});
}`,
},
},
]),
// inspect(),
],
resolve: {
alias: {
// for TypeScript path alias import like : @/x/y/z
'@': fileURLToPath(new URL('./resources/app', import.meta.url)),
'ziggy-js': resolve('vendor/tightenco/ziggy'),
},
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
additionalData: '@import "/resources/app/mantine";',
},
},
},
};
});