Import dependencies dynamically to reduce production size

This commit is contained in:
wvffle 2022-07-31 20:32:38 +00:00 committed by Georg Krause
parent cac12a85fb
commit d7052c44e0
1 changed files with 13 additions and 9 deletions

View File

@ -2,14 +2,14 @@ import type { InitModule } from '~/types'
import type { Router } from 'vue-router' import type { Router } from 'vue-router'
import type { App } from 'vue' import type { App } from 'vue'
import * as Sentry from '@sentry/vue' const COOKIE = 'allow-tracing2'
import { BrowserTracing } from '@sentry/tracing'
import { useCookies } from '@vueuse/integrations/useCookies'
import { gettext } from '~/init/locale'
const COOKIE = 'allow-tracing' const initSentry = async (app: App, router: Router) => {
const [{ BrowserTracing }, Sentry] = await Promise.all([
import('@sentry/tracing'),
import('@sentry/vue')
])
const initSentry = (app: App, router: Router) => {
Sentry.init({ Sentry.init({
app, app,
dsn: import.meta.env.VUE_SENTRY_DSN, dsn: import.meta.env.VUE_SENTRY_DSN,
@ -27,8 +27,13 @@ const initSentry = (app: App, router: Router) => {
}) })
} }
export const install: InitModule = ({ app, router, store }) => { export const install: InitModule = async ({ app, router, store }) => {
if (import.meta.env.VUE_SENTRY_DSN) { if (import.meta.env.VUE_SENTRY_DSN) {
const [{ useCookies }, { gettext: { $pgettext } }] = await Promise.all([
import('@vueuse/integrations/useCookies'),
import('~/init/locale')
])
const { get, set } = useCookies() const { get, set } = useCookies()
const allowed = get(COOKIE) const allowed = get(COOKIE)
@ -38,7 +43,6 @@ export const install: InitModule = ({ app, router, store }) => {
} }
if (allowed === undefined) { if (allowed === undefined) {
const { $pgettext } = gettext
const { hostname, origin } = new URL(import.meta.env.VUE_SENTRY_DSN) const { hostname, origin } = new URL(import.meta.env.VUE_SENTRY_DSN)
return store.commit('ui/addMessage', { return store.commit('ui/addMessage', {
content: hostname === 'am.funkwhale.audio' content: hostname === 'am.funkwhale.audio'
@ -62,7 +66,7 @@ export const install: InitModule = ({ app, router, store }) => {
class: 'primary', class: 'primary',
click: () => { click: () => {
set(COOKIE, 'yes') set(COOKIE, 'yes')
initSentry(app, router) return initSentry(app, router)
} }
}, },
{ {