UNPKG

@posthog/nextjs-config

Version:

NextJS configuration helper for Posthog 🦔

82 lines (81 loc) • 3.69 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { SourcemapWebpackPlugin: ()=>SourcemapWebpackPlugin }); const external_path_namespaceObject = require("path"); var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject); const external_utils_js_namespaceObject = require("./utils.js"); class SourcemapWebpackPlugin { apply(compiler) { if ('edge' === this.nextRuntime) return; const onDone = async (_, callback)=>{ callback = callback || (()=>{}); try { this.posthogOptions.verbose && console.log('Processing source maps from webpack plugin...'); const posthogOptions = { ...this.posthogOptions, sourcemaps: { ...this.posthogOptions.sourcemaps, deleteAfterUpload: this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer } }; await (0, external_utils_js_namespaceObject.processSourceMaps)(posthogOptions, this.directory); } catch (error) { const errorMessage = error instanceof Error ? error.message : error; return console.error('Error running PostHog sourcemap plugin:', errorMessage); } return callback(); }; if (compiler.hooks) compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone); else compiler.plugin('done', onDone); } constructor(posthogOptions, isServer, nextRuntime, distDir){ this.posthogOptions = posthogOptions; this.isServer = isServer; this.nextRuntime = nextRuntime; const resolvedDistDir = external_path_default().resolve(null != distDir ? distDir : '.next'); if (!this.posthogOptions.personalApiKey) throw new Error("Personal API key not provided. If you are using turbo, make sure to add env variables to your turbo config"); if (!this.posthogOptions.envId) throw new Error("Environment ID not provided. If you are using turbo, make sure to add env variables to your turbo config"); this.directory = this.isServer ? external_path_default().join(resolvedDistDir, 'server') : external_path_default().join(resolvedDistDir, 'static/chunks'); } } exports.SourcemapWebpackPlugin = __webpack_exports__.SourcemapWebpackPlugin; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "SourcemapWebpackPlugin" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true });