-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
Copy pathvite.config.mts
123 lines (115 loc) · 2.98 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
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import { defineConfig, mergeConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import svgLoader from 'vite-svg-loader';
import { vitestConfig } from '@n8n/frontend-vitest-config';
import icons from 'unplugin-icons/vite';
import iconsResolver from 'unplugin-icons/resolver';
import components from 'unplugin-vue-components/vite';
import browserslistToEsbuild from 'browserslist-to-esbuild';
import legacy from '@vitejs/plugin-legacy';
import browserslist from 'browserslist';
const publicPath = process.env.VUE_APP_PUBLIC_PATH || '/';
const { NODE_ENV } = process.env;
const browsers = browserslist.loadConfig({ path: process.cwd() });
const alias = [
{ find: '@', replacement: resolve(__dirname, 'src') },
{ find: 'stream', replacement: 'stream-browserify' },
{
find: /^n8n-design-system$/,
replacement: resolve(__dirname, '..', 'design-system', 'src', 'index.ts'),
},
{
find: /^n8n-design-system\//,
replacement: resolve(__dirname, '..', 'design-system', 'src') + '/',
},
{
find: /^@n8n\/chat$/,
replacement: resolve(__dirname, '..', '@n8n', 'chat', 'src', 'index.ts'),
},
{
find: /^@n8n\/chat\//,
replacement: resolve(__dirname, '..', '@n8n', 'chat', 'src') + '/',
},
{
find: /^@n8n\/composables(.+)$/,
replacement: resolve(__dirname, '..', 'frontend', '@n8n', 'composables', 'src$1'),
},
...['orderBy', 'camelCase', 'cloneDeep', 'startCase'].map((name) => ({
find: new RegExp(`^lodash.${name}$`, 'i'),
replacement: `lodash-es/${name}`,
})),
{
find: /^lodash\.(.+)$/,
replacement: 'lodash-es/$1',
},
];
const plugins = [
icons({
compiler: 'vue3',
autoInstall: true,
}),
components({
dts: './src/components.d.ts',
resolvers: [
iconsResolver({
prefix: 'icon',
}),
],
}),
viteStaticCopy({
targets: [
{ src: resolve('node_modules/web-tree-sitter/tree-sitter.wasm'), dest: '' },
{ src: resolve('node_modules/curlconverter/dist/tree-sitter-bash.wasm'), dest: '' },
],
}),
vue(),
svgLoader(),
legacy({
modernTargets: browsers,
modernPolyfills: true,
renderLegacyChunks: false,
}),
];
const { RELEASE: release } = process.env;
const target = browserslistToEsbuild(browsers);
export default mergeConfig(
defineConfig({
define: {
// This causes test to fail but is required for actually running it
// ...(NODE_ENV !== 'test' ? { 'global': 'globalThis' } : {}),
...(NODE_ENV === 'development' ? { 'process.env': {} } : {}),
BASE_PATH: `'${publicPath}'`,
},
plugins,
resolve: { alias },
base: publicPath,
envPrefix: 'VUE_APP',
css: {
preprocessorOptions: {
scss: {
additionalData: [
'',
'@use "@/n8n-theme-variables.scss" as *;',
'@use "n8n-design-system/css/mixins" as mixins;',
].join('\n'),
},
},
},
build: {
minify: !!release,
sourcemap: !!release,
target,
},
optimizeDeps: {
esbuildOptions: {
target,
},
},
worker: {
format: 'es',
},
}),
vitestConfig,
);