Skip to content

Commit

Permalink
sentry lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Mineev committed Nov 9, 2024
1 parent 4efe564 commit 02da7d5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docker-compose run --rm hugo

## публикация подкаста

Перед использованием, необходимо иметь собранный docker образ `publisher`. Команда сборки при помощи docker-compose (конфиг в руте репозитария): `docker-compose build publisher`.
Перед использованием, необходимо иметь собранный docker образ `publisher`. Команда сборки при помощи docker-compose (конфиг в руте репозитория): `docker-compose build publisher`.

Скрипты публикации могут быть вызваны при помощи make в директории `./publisher`:

Expand All @@ -25,6 +25,14 @@ docker-compose run --rm hugo

## фронтенд

### зависимости

- [Node v22](https://nodejs.org/en/download/package-manager)
- [GoLang](https://go.dev/doc/install)
- [Hugo v0.81.0](https://gohugo.io/installation/macos/#build-from-source)

### девелопмент

```bash
# node 10
cd hugo
Expand All @@ -33,17 +41,19 @@ npm install

# разработка на localhost:3000
# с hugo LiveReload, без turbolinks
npm run start
npm run dev
# без hugo LiveReload, с turbolinks
npm run start-turbo
npm run dev:turbo

# сборка для прода
# сборка для prod
# результаты сборки:
# - hugo/static/build/
# - hugo/data/manifest.json
npm run production
```

### файловая структура

- лого в `src/images/`
- фавиконки в `static/` и описаны в `layouts/partials/favicons.html`
- favicons в `static/` и описаны в `layouts/partials/favicons.html`
- обложки в `static/images/covers/` (для сохранения совместимости также оставлены обложки `static/images/cover.jpg` и `static/images/cover_rt_big_archive.png`)
16 changes: 2 additions & 14 deletions hugo/src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
// TODO: fix babel-loader and use import
require('./polyfills');
import './sentry'

let sentryInitialized = false;

async function loadSentry() {
if (!sentryInitialized) {
sentryInitialized = true;
const {initSentry} = import('./sentry');
await initSentry();
}
}

if (process.env.NODE_ENV !== 'production') {
// Include here for dev, but inline for prod
Expand All @@ -23,8 +15,4 @@ if (process.env.NODE_ENV === 'production' || process.env.MIX_TURBO) {
require('./quicklink');
}

// Lazy load Sentry only on error
if (process.env.NODE_ENV === 'production' || process.env.ENABLE_SENTRY) {
window.addEventListener('error', loadSentry);
window.addEventListener('unhandledrejection', loadSentry);
}

27 changes: 20 additions & 7 deletions hugo/src/js/sentry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
export function initSentry() {
const Sentry = import('@sentry/browser');
Sentry.init({
dsn: 'https://[email protected]/1467904',
});
return Sentry;
}
let Sentry;

/** Lazy load Sentry on error */
async function handleException(errorEvent) {
try {
if (Sentry === undefined) {
Sentry = await import('@sentry/browser');
Sentry.init({
dsn: 'https://[email protected]/4508265848897536',
enabled: process.env.NODE_ENV === 'production' || process.env.ENABLE_SENTRY,
});
}
Sentry.captureException(errorEvent);
} catch (e) {
console.error('Logging to Sentry failed', e);
}
}

window.addEventListener('error', handleException);
window.addEventListener('unhandledrejection', handleException);
14 changes: 12 additions & 2 deletions hugo/webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ mix
},
})
.ts('src/js/app.js', '.')
.extract(['@sentry/browser'], 'vendor~sentry.js')
.version();


// Process CSS with conditional minification
['app', 'vendor'].forEach((style) => {
mix
Expand Down Expand Up @@ -77,7 +79,7 @@ mix.webpackConfig({
},
],
}),
],
]
});

if (process.env.ANALYZE) {
Expand Down Expand Up @@ -138,4 +140,12 @@ if (mix.inProduction()) {
},
},
});
}
}
mix.webpackConfig({
output: {
publicPath: '/build',
},
optimization: {
splitChunks: 'all',
},
})

0 comments on commit 02da7d5

Please sign in to comment.