ui: lazyload sentry

This commit is contained in:
undefined committed 2024-08-09 01:14:46 +08:00
1 parent 977b6f2575
commit ef4862d785
4 files changed
+43 -31

No files matched your search

+6 -5
View File
@@ -23,7 +23,7 @@ const {
list, list,
targets, targets,
} = compat({ } = compat({
targets: '> 1%, chrome 70, firefox 60, safari 16, ios_saf 16, not ie 11, not op_mini all', targets: '> 1%, chrome 70, firefox 90, safari 16, ios_saf 16, not ie 11, not op_mini all',
modules: [ modules: [
'core-js/stable', 'core-js/stable',
], ],
@@ -99,6 +99,7 @@ export default async function (env: { watch?: boolean, production?: boolean, mea
devtool: env.production ? 'source-map' : false, devtool: env.production ? 'source-map' : false,
entry: { entry: {
[`hydro-${version}`]: './entry.js', [`hydro-${version}`]: './entry.js',
'sentry': './sentry.ts',
'default.theme': './theme/default.js', 'default.theme': './theme/default.js',
'service-worker': './service-worker.ts', 'service-worker': './service-worker.ts',
}, },
@@ -209,9 +210,9 @@ export default async function (env: { watch?: boolean, production?: boolean, mea
}, },
optimization: { optimization: {
splitChunks: { splitChunks: {
minSize: 256000, minSize: 64000,
maxAsyncRequests: 5, maxAsyncRequests: 10,
maxInitialRequests: 3, maxInitialRequests: 7,
automaticNameDelimiter: '-', automaticNameDelimiter: '-',
cacheGroups: { cacheGroups: {
style: { style: {
@@ -222,7 +223,7 @@ export default async function (env: { watch?: boolean, production?: boolean, mea
enforce: true, enforce: true,
}, },
vendors: { vendors: {
test: /[\\/]node_modules[\\/].+\.([jt]sx?|json|yaml)$/, test: /[\\/]node_modules[\\/].+\.(m?[jt]sx?|json|yaml)$/,
priority: -10, priority: -10,
name(module) { name(module) {
const packageName = module.context.replace(/\\/g, '/').split('node_modules/').pop().split('/')[0]; const packageName = module.context.replace(/\\/g, '/').split('node_modules/').pop().split('/')[0];
+9 -24
View File
@@ -1,6 +1,5 @@
import './polyfill'; import './polyfill';
import * as Sentry from '@sentry/browser';
import $ from 'jquery'; import $ from 'jquery';
window.Hydro = { window.Hydro = {
@@ -30,29 +29,6 @@ console.log(
window.UiContext = JSON.parse(window.UiContext); window.UiContext = JSON.parse(window.UiContext);
window.UserContext = JSON.parse(window.UserContext); window.UserContext = JSON.parse(window.UserContext);
if (process.env.NODE_ENV === 'production' && UiContext.sentry_dsn) {
window.captureException = (e) => {
if (!e.isUserFacingError) Sentry.captureException(e);
};
Sentry.init({
dsn: UiContext.sentry_dsn,
release: `hydro-web@${process.env.VERSION}`,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.browserApiErrorsIntegration(),
Sentry.replayIntegration({
networkRequestHeaders: ['Content-Type'],
networkResponseHeaders: ['Content-Type', 'Location'],
}),
],
tracesSampleRate: 0.1,
tracePropagationTargets: ['localhost', /^\//, window.location.host],
replaysSessionSampleRate: 0.01,
replaysOnErrorSampleRate: 0.2,
});
Sentry.setTag('host', window.location.host);
Sentry.setTag('page_name', document.documentElement.getAttribute('data-page'));
}
try { __webpack_public_path__ = UiContext.cdn_prefix; } catch (e) { } try { __webpack_public_path__ = UiContext.cdn_prefix; } catch (e) { }
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
const encodedConfig = encodeURIComponent(JSON.stringify(UiContext.SWConfig)); const encodedConfig = encodeURIComponent(JSON.stringify(UiContext.SWConfig));
@@ -66,6 +42,15 @@ if ('serviceWorker' in navigator) {
const PageLoader = '<div class="page-loader nojs--hide" style="display:none;"><div class="loader"></div></div>'; const PageLoader = '<div class="page-loader nojs--hide" style="display:none;"><div class="loader"></div></div>';
$('body').prepend(PageLoader); $('body').prepend(PageLoader);
$('.page-loader').fadeIn(500); $('.page-loader').fadeIn(500);
if (process.env.NODE_ENV === 'production' && UiContext.sentry_dsn) {
window._sentryEvents = [];
window.captureException = (e) => {
if (!e.isUserFacingError) window._sentryEvents.push(e);
};
const script = document.createElement('script');
script.src = new URL('sentry.js', __webpack_public_path__).href;
document.body.appendChild(script);
}
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
Object.assign(window.UiContext, JSON.parse(window.UiContextNew)); Object.assign(window.UiContext, JSON.parse(window.UiContextNew));
+26
View File
@@ -0,0 +1,26 @@
import {
browserApiErrorsIntegration, browserTracingIntegration, captureException, init, replayIntegration, setTag,
} from '@sentry/browser';
init({
dsn: UiContext.sentry_dsn,
release: `hydro-web@${process.env.VERSION}`,
integrations: [
browserTracingIntegration(),
browserApiErrorsIntegration(),
replayIntegration({
networkRequestHeaders: ['Content-Type'],
networkResponseHeaders: ['Content-Type', 'Location'],
}),
],
tracesSampleRate: 0.1,
tracePropagationTargets: ['localhost', /^\//, window.location.host],
replaysSessionSampleRate: 0.01,
replaysOnErrorSampleRate: 0.1,
});
setTag('host', window.location.host);
setTag('page_name', document.documentElement.getAttribute('data-page'));
window.captureException = (e: any) => {
if (!e.isUserFacingError) captureException(e);
};
(window as any)._sentryEvents.forEach(captureException);
+2 -2
View File
@@ -89,7 +89,7 @@ self.addEventListener('notificationclick', (event) => {
}); });
const PRECACHE = `precache-${process.env.VERSION}`; const PRECACHE = `precache-${process.env.VERSION}`;
const DO_NOT_PRECACHE = ['.worker.js', 'fonts', 'i.monaco']; const DO_NOT_PRECACHE = ['.worker.js', 'fonts'];
function shouldCachePath(path: string) { function shouldCachePath(path: string) {
if (!path.split('?')[0].split('/').pop()) return false; if (!path.split('?')[0].split('/').pop()) return false;
@@ -121,7 +121,7 @@ let config: ServiceWorkerConfig = null;
function initConfig() { function initConfig() {
config = JSON.parse(new URLSearchParams(location.search).get('config')); config = JSON.parse(new URLSearchParams(location.search).get('config'));
config.hosts ||= []; config.hosts ||= [];
if (!config.domains?.length) config.domains = [location.host]; config.domains = Array.from(new Set([location.host, ...(config.domains || [])]));
console.log('Config:', config); console.log('Config:', config);
} }