-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: significantly reduce client bundle size (#547)
- Loading branch information
Showing
7 changed files
with
121 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<% | ||
if (options.clientConfigPath) {%>import getClientConfig from '<%= options.clientConfigPath %>' | ||
<%} | ||
if (options.customClientIntegrations) {%>import getCustomIntegrations from '<%= options.customClientIntegrations %>' | ||
<%}%> | ||
import merge from '~lodash.mergewith' | ||
<% | ||
const browserIntegrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations) | ||
const vueImports = [ | ||
'init', | ||
...(browserIntegrations.length ? ['Integrations'] : []), | ||
...(options.tracing ? ['vueRouterInstrumentation'] : []) | ||
] | ||
%>import { <%= vueImports.join(', ') %> } from '~@sentry/vue' | ||
import * as CoreSdk from '~@sentry/core' | ||
import * as BrowserSdk from '~@sentry/browser-sdk' | ||
<% | ||
if (options.tracing) {%>import { BrowserTracing } from '~@sentry/tracing' | ||
<%} | ||
let integrations = options.BROWSER_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations) | ||
if (integrations.length) {%>import { <%= integrations.join(', ') %> } from '~@sentry/integrations' | ||
<%}%> | ||
|
||
export { init } | ||
export const SentrySdk = { ...CoreSdk, ...BrowserSdk } | ||
|
||
export<%= (options.clientConfigPath || options.customClientIntegrations) ? ' async' : '' %> function getConfig (ctx) { | ||
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */ | ||
const config = { | ||
<%= Object | ||
.entries(options.config) | ||
.map(([key, option]) => { | ||
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option) | ||
return `${key}:${value}` | ||
}) | ||
.join(',\n ') %>, | ||
} | ||
|
||
<% if (browserIntegrations.length) {%> | ||
const { <%= browserIntegrations.join(', ') %> } = Integrations | ||
<%}%> | ||
config.integrations = [ | ||
<%= Object | ||
.entries(options.integrations) | ||
.filter(([name]) => name !== 'Vue') | ||
.map(([name, integration]) => { | ||
const integrationOptions = Object | ||
.entries(integration) | ||
.map(([key, option]) => { | ||
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option) | ||
return `${key}:${value}` | ||
}) | ||
|
||
return `new ${name}(${integrationOptions.length ? '{ ' + integrationOptions.join(',') + ' }' : ''})` | ||
}) | ||
.join(',\n ') %>, | ||
] | ||
<% if (options.tracing) { %> | ||
const { browserTracing, vueOptions, ...tracingOptions } = <%= serialize(options.tracing) %> | ||
config.integrations.push(new BrowserTracing({ | ||
...(ctx.app.router ? { routingInstrumentation: vueRouterInstrumentation(ctx.app.router) } : {}), | ||
...browserTracing, | ||
})) | ||
merge(config, vueOptions, tracingOptions) | ||
<% } %> | ||
|
||
<% if (options.clientConfigPath) { %> | ||
const clientConfig = await getClientConfig(ctx) | ||
clientConfig ? merge(config, clientConfig) : console.error(`[@nuxtjs/sentry] Invalid value returned from the clientConfig plugin.`) | ||
<% } %> | ||
|
||
<% if (options.customClientIntegrations) { %> | ||
const customIntegrations = await getCustomIntegrations(ctx) | ||
if (Array.isArray(customIntegrations)) { | ||
config.integrations.push(...customIntegrations) | ||
} else { | ||
console.error(`[@nuxtjs/sentry] Invalid value returned from customClientIntegrations plugin. Expected an array, got "${typeof customIntegrations}".`) | ||
} | ||
<% } %> | ||
|
||
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %> | ||
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) { | ||
merge(config, ctx.$config[runtimeConfigKey].config, ctx.$config[runtimeConfigKey].clientConfig) | ||
} | ||
|
||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,9 @@ | ||
/* eslint-disable import/order */ | ||
import Vue from 'vue' | ||
import merge from '~lodash.mergewith' | ||
import * as Sentry from '~@sentry/vue' | ||
<% | ||
if (options.tracing) { | ||
%>import { BrowserTracing } from '~@sentry/tracing' | ||
import { vueRouterInstrumentation } from '~@sentry/vue' | ||
<%} | ||
let integrations = options.BROWSER_PLUGGABLE_INTEGRATIONS.filter(key => key in options.integrations) | ||
if (integrations.length) {%>import { <%= integrations.join(', ') %> } from '~@sentry/integrations' | ||
<%} | ||
if (options.clientConfigPath) {%>import getClientConfig from '<%= options.clientConfigPath %>' | ||
<%} | ||
if (options.customClientIntegrations) {%>import getCustomIntegrations from '<%= options.customClientIntegrations %>' | ||
<%} | ||
integrations = options.BROWSER_INTEGRATIONS.filter(key => key in options.integrations) | ||
if (integrations.length) {%> | ||
const { <%= integrations.join(', ') %> } = Sentry.Integrations | ||
<%} | ||
%> | ||
import { getConfig, init, SentrySdk } from './sentry.client.shared' | ||
|
||
export default async function (ctx, inject) { | ||
/* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */ | ||
const config = { | ||
Vue, | ||
<%= Object | ||
.entries(options.config) | ||
.map(([key, option]) => { | ||
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option) | ||
return `${key}:${value}` | ||
}) | ||
.join(',\n ') %>, | ||
} | ||
|
||
config.integrations = [ | ||
<%= Object | ||
.entries(options.integrations) | ||
.filter(([name]) => name !== 'Vue') | ||
.map(([name, integration]) => { | ||
const integrationOptions = Object | ||
.entries(integration) | ||
.map(([key, option]) => { | ||
const value = typeof option === 'function' ? serializeFunction(option) : serialize(option) | ||
return `${key}:${value}` | ||
}) | ||
|
||
return `new ${name}(${integrationOptions.length ? '{ ' + integrationOptions.join(',') + ' }' : ''})` | ||
}) | ||
.join(',\n ') %>, | ||
] | ||
<% if (options.tracing) { %> | ||
// eslint-disable-next-line prefer-regex-literals | ||
const { browserTracing, vueOptions, ...tracingOptions } = <%= serialize(options.tracing) %> | ||
config.integrations.push(new BrowserTracing({ | ||
...(ctx.app.router ? { routingInstrumentation: vueRouterInstrumentation(ctx.app.router) } : {}), | ||
...browserTracing, | ||
})) | ||
merge(config, vueOptions, tracingOptions) | ||
<% } %> | ||
|
||
<% if (options.clientConfigPath) { %> | ||
const clientConfig = await getClientConfig(ctx) | ||
clientConfig ? merge(config, clientConfig) : console.error(`[@nuxtjs/sentry] Invalid value returned from the clientConfig plugin.`) | ||
<% } %> | ||
|
||
<% if (options.customClientIntegrations) { %> | ||
const customIntegrations = await getCustomIntegrations(ctx) | ||
if (Array.isArray(customIntegrations)) { | ||
config.integrations.push(...customIntegrations) | ||
} else { | ||
console.error(`[@nuxtjs/sentry] Invalid value returned from customClientIntegrations plugin. Expected an array, got "${typeof customIntegrations}".`) | ||
} | ||
<% } %> | ||
|
||
const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %> | ||
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) { | ||
merge(config, ctx.$config[runtimeConfigKey].config, ctx.$config[runtimeConfigKey].clientConfig) | ||
} | ||
|
||
/* eslint-enable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */ | ||
Sentry.init(config) | ||
inject('sentry', Sentry) | ||
ctx.$sentry = Sentry | ||
const config = await getConfig(ctx) | ||
init({ Vue, ...config }) | ||
inject('sentry', SentrySdk) | ||
ctx.$sentry = SentrySdk | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"exclude": [ | ||
"./dist", | ||
"./node_modules/", | ||
"./src/templates/client.*.js", | ||
"./src/templates/plugin.*.js", | ||
] | ||
} |