📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Migrate to Vite
Blue Mouse0b7971eaa8c4
diff --git a/.gitignore b/.gitignoreindex a4cb83216..83e8ddf2b 100644--- a/.gitignore+++ b/.gitignore@@ -62,3 +62,4 @@ web/buildweb/public/buildcrowdin.yml.cache+web/vite.config.ts.timestamp*diff --git a/web/app/api/index.ts b/web/app/api/index.tsindex 730305e6b..b83266531 100644--- a/web/app/api/index.ts+++ b/web/app/api/index.ts@@ -1,11 +1,11 @@/* eslint-disable implicit-arrow-linebreak */import axios, { AxiosResponse } from 'axios'import createAuthRefreshInterceptor from 'axios-auth-refresh'-import { store } from '~/lib/store'import _map from 'lodash/map'import _isEmpty from 'lodash/isEmpty'import _isArray from 'lodash/isArray'+import { store } from '~/lib/store'import { authActions } from '~/lib/reducers/auth'import { getAccessToken, removeAccessToken, setAccessToken } from '~/utils/accessToken'import { getRefreshToken, removeRefreshToken } from '~/utils/refreshToken'diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsxindex 0d4e26f17..c1952f671 100644--- a/web/app/pages/Project/View/ViewProject.helpers.tsx+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx@@ -1,7 +1,7 @@import React from 'react'import type { ChartOptions, GridLineOptions } from 'billboard.js'import type i18next from 'i18next'-import { saveAs } from 'file-saver'+import filesaver from 'file-saver'import { LanguageIcon, ArrowRightCircleIcon } from '@heroicons/react/24/outline'import dayjs from 'dayjs'import { area, areaSpline, spline, bar, line } from 'billboard.js'@@ -52,6 +52,8 @@ import {WatchIcon,} from 'lucide-react'+const { saveAs } = filesaver+const getAvg = (arr: any) => {const total = _reduce(arr, (acc, c) => acc + c, 0)return total / _size(arr)diff --git a/web/app/pages/Project/View/ViewProject.tsx b/web/app/pages/Project/View/ViewProject.tsxindex 5d72ffa7b..9b9711754 100644--- a/web/app/pages/Project/View/ViewProject.tsx+++ b/web/app/pages/Project/View/ViewProject.tsx@@ -53,6 +53,7 @@ import _size from 'lodash/size'import _truncate from 'lodash/truncate'import _isString from 'lodash/isString'import { toast } from 'sonner'+import SwetrixSDK from '@swetrix/sdk'import { periodToCompareDate } from '~/utils/compareConvertDate'@@ -207,7 +208,6 @@ import { StateType, useAppDispatch } from '~/lib/store'import UIActions from '~/lib/reducers/ui'import { useSelector } from 'react-redux'import PageDropdown from './components/PageDropdown'-const SwetrixSDK = require('@swetrix/sdk')const CUSTOM_EV_DROPDOWN_MAX_VISIBLE_LENGTH = 32const SESSIONS_TAKE = 30@@ -2383,7 +2383,7 @@ const ViewProject = () => {onRemoveExportDataRow: (label: any) => {setCustomExportTypes((prev) => _filter(prev, (row) => row.label !== label))},- onAddPanelTab: (extensionID: string, panelID: string, tabContent: any, onOpen: (a: any) => void) => {+ onAddPanelTab: (extensionID: string, panelID: string, tabContent?: string, onOpen?: (a: any) => void) => {setCustomPanelTabs((prev) => [...prev,{diff --git a/web/app/root.tsx b/web/app/root.tsxindex 7f63e7da3..6ccb866c1 100644--- a/web/app/root.tsx+++ b/web/app/root.tsx@@ -4,7 +4,6 @@ import { data, redirect } from '@remix-run/node'import { useState } from 'react'import {Links,- LiveReload,Meta,Scripts,useLoaderData,@@ -20,7 +19,7 @@ import { ExclamationTriangleIcon, ChevronDownIcon, ChevronUpIcon } from '@heroicimport { Provider } from 'react-redux'import cx from 'clsx'import _replace from 'lodash/replace'-import BillboardCss from 'billboard.js/dist/billboard.min.css'+import BillboardCss from 'billboard.js/dist/billboard.min.css?url'import { trackViews, trackErrors } from '~/utils/analytics'import { useChangeLanguage } from 'remix-i18next/react'@@ -31,13 +30,13 @@ import { detectTheme, isAuthenticated, isWWW } from '~/utils/server'import { LocaleLinks } from '~/components/LocaleLinks'import { SEO } from '~/components/SEO'-import mainCss from '~/styles/index.css'-import tailwindCss from '~/styles/tailwind.css'-import sonnerCss from '~/styles/sonner.css'-import FlatpickerCss from '~/styles/Flatpicker.css'-import FlatpickrLightCss from 'flatpickr/dist/themes/light.css'-import FlatpickrDarkCss from 'flatpickr/dist/themes/dark.css'-import FontsCss from '~/styles/fonts.css'+import mainCss from '~/styles/index.css?url'+import tailwindCss from '~/styles/tailwind.css?url'+import sonnerCss from '~/styles/sonner.css?url'+import FlatpickerCss from '~/styles/Flatpicker.css?url'+import FlatpickrLightCss from 'flatpickr/dist/themes/light.css?url'+import FlatpickrDarkCss from 'flatpickr/dist/themes/dark.css?url'+import FontsCss from '~/styles/fonts.css?url'trackViews()trackErrors()@@ -148,7 +147,6 @@ export function ErrorBoundary() {</div><ScrollRestoration /><Scripts />- <LiveReload /></body></html>)@@ -266,7 +264,6 @@ export default function App() {<ScrollRestoration /><ExternalScripts /><Scripts />- <LiveReload /></body></html>)diff --git a/web/app/routes/index.tsx b/web/app/routes/_index.tsxsimilarity index 99%rename from web/app/routes/index.tsxrename to web/app/routes/_index.tsxindex 737830822..75603508a 100644--- a/web/app/routes/index.tsx+++ b/web/app/routes/_index.tsx@@ -49,6 +49,7 @@ export const sitemap: SitemapFunction = () => ({})export async function loader({ request }: LoaderFunctionArgs) {+ console.log('Index loader')if (isSelfhosted || isDisableMarketingPages) {return redirect('/login', 302)}@@ -887,6 +888,8 @@ const Hero = ({export default function Index() {const { theme: ssrTheme, isAuth } = useLoaderData<typeof loader>()+ console.log('Index component')+const reduxTheme = useSelector((state: StateType) => state.ui.theme.theme)const { authenticated: reduxAuthenticated, loading } = useSelector((state: StateType) => state.auth)const theme = isBrowser ? reduxTheme : ssrThemediff --git a/web/app/routes/blog.tsx b/web/app/routes/blog._index.tsxsimilarity index 100%rename from web/app/routes/blog.tsxrename to web/app/routes/blog._index.tsxdiff --git a/web/app/routes/captchas.$id.tsx b/web/app/routes/captchas.$id.tsxindex d26627f3c..3ea76363a 100644--- a/web/app/routes/captchas.$id.tsx+++ b/web/app/routes/captchas.$id.tsx@@ -1,6 +1,6 @@import CaptchaView from '~/pages/Captcha/View'import type { LinksFunction, LoaderFunctionArgs } from '@remix-run/node'-import ProjectViewStyle from '~/styles/ProjectViewStyle.css'+import ProjectViewStyle from '~/styles/ProjectViewStyle.css?url'import { detectTheme } from '~/utils/server'import { useLoaderData } from '@remix-run/react'diff --git a/web/app/routes/open.tsx b/web/app/routes/open.tsxindex fbb12f1df..e4b4a222b 100644--- a/web/app/routes/open.tsx+++ b/web/app/routes/open.tsx@@ -3,7 +3,7 @@ import { redirect } from '@remix-run/node'import type { LinksFunction } from '@remix-run/node'import { isDisableMarketingPages, isSelfhosted } from '~/lib/constants'import type { SitemapFunction } from 'remix-sitemap'-import Style from '~/styles/ProjectViewStyle.css'+import Style from '~/styles/ProjectViewStyle.css?url'export const links: LinksFunction = () => {return [{ rel: 'stylesheet', href: Style }]diff --git a/web/app/routes/projects.$id.tsx b/web/app/routes/projects.$id.tsxindex 7b361e7a0..e61f79ca3 100644--- a/web/app/routes/projects.$id.tsx+++ b/web/app/routes/projects.$id.tsx@@ -4,7 +4,7 @@ import _split from 'lodash/split'import { API_URL } from '~/lib/constants'import { detectTheme, isEmbedded, isAuthenticated, getProjectPassword, getProjectTabs } from '~/utils/server'-import ProjectViewStyle from '~/styles/ProjectViewStyle.css'+import ProjectViewStyle from '~/styles/ProjectViewStyle.css?url'export const links: LinksFunction = () => [{ rel: 'stylesheet', href: ProjectViewStyle }]diff --git a/web/app/ui/Chart.tsx b/web/app/ui/Chart.tsxindex 183f2036b..11607e1de 100644--- a/web/app/ui/Chart.tsx+++ b/web/app/ui/Chart.tsx@@ -1,7 +1,7 @@import React, { useEffect } from 'react'import bb from 'billboard.js'-import 'billboard.js/dist/theme/datalab.css'-import 'billboard.js/dist/billboard.css'+import 'billboard.js/dist/theme/datalab.css?url'+import 'billboard.js/dist/billboard.css?url'// Define the prop types for the componentinterface ChartProps {diff --git a/web/package-lock.json b/web/package-lock.jsonindex bfc1a581f..8d73e1781 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -79,7 +79,9 @@"postcss": "^8.5.1","prettier": "^3.4.2","tailwindcss": "^4.0.4",- "typescript": "^5.7.3"+ "typescript": "^5.7.3",+ "vite": "^5.4.14",+ "vite-tsconfig-paths": "^5.1.4"},"engines": {"node": ">=20"@@ -6880,6 +6882,13 @@"url": "https://github.com/sponsors/sindresorhus"}},+ "node_modules/globrex": {+ "version": "0.1.2",+ "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz",+ "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==",+ "dev": true,+ "license": "MIT"+ },"node_modules/gopd": {"version": "1.0.1","license": "MIT",@@ -11960,6 +11969,27 @@"typescript": ">=4.8.4"}},+ "node_modules/tsconfck": {+ "version": "3.1.5",+ "resolved": "https://registry.npmjs.org/tsconfck/-/tsconfck-3.1.5.tgz",+ "integrity": "sha512-CLDfGgUp7XPswWnezWwsCRxNmgQjhYq3VXHM0/XIRxhVrKw0M1if9agzryh1QS3nxjCROvV+xWxoJO1YctzzWg==",+ "dev": true,+ "license": "MIT",+ "bin": {+ "tsconfck": "bin/tsconfck.js"+ },+ "engines": {+ "node": "^18 || >=20"+ },+ "peerDependencies": {+ "typescript": "^5.0.0"+ },+ "peerDependenciesMeta": {+ "typescript": {+ "optional": true+ }+ }+ },"node_modules/tsconfig-paths": {"version": "4.2.0","license": "MIT",@@ -12575,6 +12605,26 @@"url": "https://opencollective.com/vitest"}},+ "node_modules/vite-tsconfig-paths": {+ "version": "5.1.4",+ "resolved": "https://registry.npmjs.org/vite-tsconfig-paths/-/vite-tsconfig-paths-5.1.4.tgz",+ "integrity": "sha512-cYj0LRuLV2c2sMqhqhGpaO3LretdtMn/BVX4cPLanIZuwwrkVl+lK84E/miEXkCHWXuq65rhNN4rXsBcOB3S4w==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "debug": "^4.1.1",+ "globrex": "^0.1.2",+ "tsconfck": "^3.0.3"+ },+ "peerDependencies": {+ "vite": "*"+ },+ "peerDependenciesMeta": {+ "vite": {+ "optional": true+ }+ }+ },"node_modules/vite/node_modules/@esbuild/darwin-arm64": {"version": "0.21.5","cpu": [diff --git a/web/package.json b/web/package.jsonindex 70bbf04ba..39ef64409 100644--- a/web/package.json+++ b/web/package.json@@ -1,15 +1,16 @@{"private": true,"sideEffects": false,+ "type": "module","license": "AGPL-3.0","scripts": {- "build": "remix build",- "dev": "remix dev",+ "build": "remix vite:build",+ "dev": "remix vite:dev","deploy": "flyctl deploy --remote-only","import-env": "node fly_import_env.js --env-file .env",- "dev:staging": "cross-env STAGING=true remix dev",- "start": "remix-serve ./build/index.js",- "start:staging": "cross-env STAGING=true remix-serve ./build/index.js",+ "dev:staging": "cross-env STAGING=true remix vite:dev",+ "start": "remix-serve ./build/server/index.js",+ "start:staging": "cross-env STAGING=true remix-serve ./build/server/index.js","typecheck": "tsc","lint": "eslint app","lint:fix": "eslint app --fix",@@ -149,7 +150,9 @@"postcss": "^8.5.1","prettier": "^3.4.2","tailwindcss": "^4.0.4",- "typescript": "^5.7.3"+ "typescript": "^5.7.3",+ "vite": "^5.4.14",+ "vite-tsconfig-paths": "^5.1.4"},"engines": {"node": ">=20"diff --git a/web/postcss.config.js b/web/postcss.config.cjssimilarity index 100%rename from web/postcss.config.jsrename to web/postcss.config.cjsdiff --git a/web/remix.config.js b/web/remix.config.jsdeleted file mode 100644index 2e06b549d..000000000--- a/web/remix.config.js+++ /dev/null@@ -1,42 +0,0 @@-const { createRoutesFromFolders } = require('@remix-run/v1-route-convention')--/** @type {import('@remix-run/dev').AppConfig} */-module.exports = {- ignoredRouteFiles: ['**/.*'],- appDirectory: 'app',- // assetsBuildDirectory: "public/build",- // serverBuildPath: 'build/index.js',- // publicPath: "/build/",- tailwind: true,- postcss: true,- serverModuleFormat: 'cjs',- serverDependenciesToBundle: [- 'axios',- 'd3',- /^d3-*/,- 'nivo',- /^nivo-*/,- /^@nivo*/,- 'delaunator',- 'internmap',- 'robust-predicates',- 'marked',- 'billboard.js',- /^remix-utils.*/,- /^remix-i18next.*/,- 'lucide-react',- ],- // eslint-disable-next-line no-undef- serverMinify: process.env.NODE_ENV === 'production',- future: {- v3_fetcherPersist: true,- v3_throwAbortReason: true,- v3_lazyRouteDiscovery: true,- v3_singleFetch: true,- v3_relativeSplatPath: true,- },- routes(defineRoutes) {- // uses the v1 convention, works in v1.15+ and v2- return createRoutesFromFolders(defineRoutes)- },-}diff --git a/web/remix.env.d.ts b/web/remix.env.d.tsdeleted file mode 100644index dcf8c45e1..000000000--- a/web/remix.env.d.ts+++ /dev/null@@ -1,2 +0,0 @@-/// <reference types="@remix-run/dev" />-/// <reference types="@remix-run/node" />diff --git a/web/tsconfig.json b/web/tsconfig.jsonindex eb8333899..267b6b24b 100644--- a/web/tsconfig.json+++ b/web/tsconfig.json@@ -1,15 +1,16 @@{"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],"compilerOptions": {- "lib": ["DOM", "DOM.Iterable", "ES2020"],+ "lib": ["DOM", "DOM.Iterable", "ES2022"],+ "types": ["@remix-run/node", "vite/client"],"skipLibCheck": true,+ "module": "ESNext",+ "moduleResolution": "Bundler","isolatedModules": true,"esModuleInterop": true,"jsx": "react-jsx",- // We need Bundler instead of Node so IDE would not complain for imports from remix-utils/*- "moduleResolution": "Bundler","resolveJsonModule": true,- "target": "ES2019",+ "target": "ES2022","strict": true,"allowJs": true,"forceConsistentCasingInFileNames": true,diff --git a/web/vite.config.ts b/web/vite.config.tsnew file mode 100644index 000000000..71940dad5--- /dev/null+++ b/web/vite.config.ts@@ -0,0 +1,50 @@+import { vitePlugin as remix } from '@remix-run/dev'+import { defineConfig } from 'vite'+import tsconfigPaths from 'vite-tsconfig-paths'++export default defineConfig({+ server: {+ port: 3000,+ },+ optimizeDeps: {+ include: ['axios-auth-refresh', '@swetrix/sdk'],+ },+ ssr: {+ noExternal: [+ 'axios',+ 'axios-auth-refresh',+ '@swetrix/sdk',+ 'd3',+ /^d3-*/,+ 'nivo',+ /^nivo-*/,+ /^@nivo*/,+ 'delaunator',+ 'internmap',+ 'robust-predicates',+ 'marked',+ 'billboard.js',+ /^remix-utils.*/,+ /^remix-i18next.*/,+ 'lucide-react',+ ],+ optimizeDeps: {+ include: ['axios-auth-refresh', '@swetrix/sdk'],+ },+ },+ plugins: [+ remix({+ ignoredRouteFiles: ['**/.*'],+ appDirectory: 'app',+ future: {+ v3_fetcherPersist: true,+ v3_throwAbortReason: true,+ v3_lazyRouteDiscovery: true,+ v3_singleFetch: true,+ v3_relativeSplatPath: true,+ unstable_optimizeDeps: true,+ },+ }),+ tsconfigPaths(),+ ],+})