2023-07-28 00:51:07 -07:00
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
import { resolve } from 'path';
|
2023-02-09 06:47:34 -08:00
|
|
|
import { defineConfig, mergeConfig } from 'vite';
|
2023-04-05 08:14:41 -07:00
|
|
|
import { sentryVitePlugin } from '@sentry/vite-plugin';
|
2023-01-26 17:09:30 -08:00
|
|
|
|
2022-09-23 07:14:28 -07:00
|
|
|
import packageJSON from './package.json';
|
2023-11-27 01:56:57 -08:00
|
|
|
import { vitestConfig } from '../design-system/vite.config.mts';
|
2024-01-09 03:11:39 -08:00
|
|
|
import icons from 'unplugin-icons/vite';
|
2024-09-17 05:10:22 -07:00
|
|
|
import iconsResolver from 'unplugin-icons/resolver';
|
2024-07-23 03:30:29 -07:00
|
|
|
import components from 'unplugin-vue-components/vite';
|
2023-03-14 05:13:21 -07:00
|
|
|
|
2022-11-09 01:01:50 -08:00
|
|
|
const vendorChunks = ['vue', 'vue-router'];
|
2024-01-09 03:11:39 -08:00
|
|
|
const n8nChunks = ['n8n-workflow', 'n8n-design-system', '@n8n/chat'];
|
2022-09-23 07:14:28 -07:00
|
|
|
const ignoreChunks = [
|
|
|
|
'@fontsource/open-sans',
|
2023-07-28 00:51:07 -07:00
|
|
|
'@vueuse/components',
|
2023-05-12 01:21:40 -07:00
|
|
|
// TODO: remove this. It's currently required by xml2js in NodeErrors
|
2023-01-26 17:09:30 -08:00
|
|
|
'stream-browserify',
|
2024-01-09 03:11:39 -08:00
|
|
|
'vue-markdown-render',
|
2022-09-23 07:14:28 -07:00
|
|
|
];
|
|
|
|
|
2022-10-13 05:28:02 -07:00
|
|
|
const isScopedPackageToIgnore = (str: string) => /@codemirror\//.test(str);
|
|
|
|
|
2022-09-23 07:14:28 -07:00
|
|
|
function renderChunks() {
|
|
|
|
const { dependencies } = packageJSON;
|
|
|
|
const chunks: Record<string, string[]> = {};
|
|
|
|
|
|
|
|
Object.keys(dependencies).forEach((key) => {
|
2023-01-26 17:09:30 -08:00
|
|
|
if ([...vendorChunks, ...n8nChunks, ...ignoreChunks].includes(key)) {
|
2022-09-23 07:14:28 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-13 05:28:02 -07:00
|
|
|
if (isScopedPackageToIgnore(key)) return;
|
|
|
|
|
2022-09-23 07:14:28 -07:00
|
|
|
chunks[key] = [key];
|
|
|
|
});
|
|
|
|
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
const publicPath = process.env.VUE_APP_PUBLIC_PATH || '/';
|
|
|
|
|
2023-02-14 07:10:39 -08:00
|
|
|
const { NODE_ENV } = process.env;
|
|
|
|
|
2023-04-05 03:39:22 -07:00
|
|
|
const alias = [
|
|
|
|
{ find: '@', replacement: resolve(__dirname, 'src') },
|
|
|
|
{ find: 'stream', replacement: 'stream-browserify' },
|
2023-07-28 00:51:07 -07:00
|
|
|
{
|
|
|
|
find: /^n8n-design-system$/,
|
|
|
|
replacement: resolve(__dirname, '..', 'design-system', 'src', 'main.ts'),
|
|
|
|
},
|
2023-04-05 03:39:22 -07:00
|
|
|
{
|
|
|
|
find: /^n8n-design-system\//,
|
|
|
|
replacement: resolve(__dirname, '..', 'design-system', 'src') + '/',
|
|
|
|
},
|
2024-01-09 03:11:39 -08:00
|
|
|
{
|
|
|
|
find: /^@n8n\/chat$/,
|
|
|
|
replacement: resolve(__dirname, '..', '@n8n', 'chat', 'src', 'index.ts'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: /^@n8n\/chat\//,
|
|
|
|
replacement: resolve(__dirname, '..', '@n8n', 'chat', 'src') + '/',
|
|
|
|
},
|
2023-07-28 00:51:07 -07:00
|
|
|
...['orderBy', 'camelCase', 'cloneDeep', 'startCase'].map((name) => ({
|
2023-04-05 03:39:22 -07:00
|
|
|
find: new RegExp(`^lodash.${name}$`, 'i'),
|
2023-11-23 02:55:02 -08:00
|
|
|
replacement: `lodash-es/${name}`,
|
2023-04-05 03:39:22 -07:00
|
|
|
})),
|
|
|
|
{
|
|
|
|
find: /^lodash\.(.+)$/,
|
|
|
|
replacement: 'lodash-es/$1',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-01-09 03:11:39 -08:00
|
|
|
const plugins = [
|
|
|
|
icons({
|
|
|
|
compiler: 'vue3',
|
2024-05-17 02:52:15 -07:00
|
|
|
autoInstall: true,
|
2024-01-09 03:11:39 -08:00
|
|
|
}),
|
2024-07-23 03:30:29 -07:00
|
|
|
components({
|
|
|
|
dts: './src/components.d.ts',
|
|
|
|
resolvers: [
|
|
|
|
iconsResolver({
|
2024-09-17 05:10:22 -07:00
|
|
|
prefix: 'icon',
|
|
|
|
}),
|
|
|
|
],
|
2024-07-23 03:30:29 -07:00
|
|
|
}),
|
2024-03-01 06:11:05 -08:00
|
|
|
vue(),
|
2024-01-09 03:11:39 -08:00
|
|
|
];
|
2024-06-10 06:23:06 -07:00
|
|
|
|
2023-04-05 08:14:41 -07:00
|
|
|
const { SENTRY_AUTH_TOKEN: authToken, RELEASE: release } = process.env;
|
|
|
|
if (release && authToken) {
|
|
|
|
plugins.push(
|
|
|
|
sentryVitePlugin({
|
|
|
|
org: 'n8nio',
|
|
|
|
project: 'instance-frontend',
|
|
|
|
// Auth tokens can be obtained from https://sentry.io/settings/account/api/auth-tokens/
|
|
|
|
// and needs the `project:releases` and `org:read` scopes
|
|
|
|
authToken,
|
|
|
|
telemetry: false,
|
2024-09-24 08:49:22 -07:00
|
|
|
release: {
|
|
|
|
name: release,
|
|
|
|
},
|
2023-04-05 08:14:41 -07:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-25 04:46:25 -07:00
|
|
|
export default mergeConfig(
|
|
|
|
defineConfig({
|
2023-01-10 05:06:12 -08:00
|
|
|
define: {
|
|
|
|
// This causes test to fail but is required for actually running it
|
2023-07-28 00:51:07 -07:00
|
|
|
// ...(NODE_ENV !== 'test' ? { 'global': 'globalThis' } : {}),
|
|
|
|
...(NODE_ENV === 'development' ? { 'process.env': {} } : {}),
|
2023-01-26 17:09:30 -08:00
|
|
|
BASE_PATH: `'${publicPath}'`,
|
2023-01-10 05:06:12 -08:00
|
|
|
},
|
2023-04-05 08:14:41 -07:00
|
|
|
plugins,
|
2023-04-05 03:39:22 -07:00
|
|
|
resolve: { alias },
|
2022-10-25 04:46:25 -07:00
|
|
|
base: publicPath,
|
|
|
|
envPrefix: 'VUE_APP',
|
|
|
|
css: {
|
|
|
|
preprocessorOptions: {
|
|
|
|
scss: {
|
|
|
|
additionalData: '\n@use "@/n8n-theme-variables.scss" as *;\n',
|
|
|
|
},
|
2022-09-23 07:14:28 -07:00
|
|
|
},
|
|
|
|
},
|
2022-10-25 04:46:25 -07:00
|
|
|
build: {
|
|
|
|
assetsInlineLimit: 0,
|
2023-04-05 08:14:41 -07:00
|
|
|
minify: !!release,
|
|
|
|
sourcemap: !!release,
|
2022-10-25 04:46:25 -07:00
|
|
|
rollupOptions: {
|
2023-04-05 08:14:41 -07:00
|
|
|
treeshake: !!release,
|
2022-10-25 04:46:25 -07:00
|
|
|
output: {
|
|
|
|
manualChunks: {
|
|
|
|
vendor: vendorChunks,
|
2023-01-26 17:09:30 -08:00
|
|
|
n8n: n8nChunks,
|
2022-10-25 04:46:25 -07:00
|
|
|
...renderChunks(),
|
|
|
|
},
|
2022-09-23 07:14:28 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-10-25 04:46:25 -07:00
|
|
|
}),
|
2023-11-07 05:19:39 -08:00
|
|
|
vitestConfig,
|
2022-10-25 04:46:25 -07:00
|
|
|
);
|