Skip to content

Commit

Permalink
Merge pull request #1863 from belgattitude/sentry-tree-shaking
Browse files Browse the repository at this point in the history
Sentry tree shaking
  • Loading branch information
belgattitude authored May 17, 2022
2 parents 86e2145 + e7680a6 commit daa1516
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
8 changes: 5 additions & 3 deletions apps/nextjs-app/.size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ try {
const pages = manifest.pages;

const limitCfg = {
defaultSize: '120kb',
defaultSize: '80kb',
pages: {
// Customize specific page limits if needed
'/_app': '160kb',
'/_app': '145kb',
'/_error': '80kb',
'/404': '100kb',
'/404': '70kb',
'/': '105kb',
'/demo': '105kb',
'/home': '100kb',
'/_monitor/sentry/csr-page': '80kb',
'/_monitor/sentry/ssr-page': '80kb',
},
};
const getPageLimits = () => {
Expand Down
37 changes: 29 additions & 8 deletions apps/nextjs-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const NEXTJS_SENTRY_UPLOAD_DRY_RUN = trueEnv.includes(
process.env?.NEXTJS_SENTRY_UPLOAD_DRY_RUN ?? 'false'
);

const NEXTJS_SENTRY_DEBUG = trueEnv.includes(
process.env?.NEXTJS_SENTRY_DEBUG ?? 'false'
);

/**
* A way to allow CI optimization when the build done there is not used
* to deliver an image or deploy the files.
Expand All @@ -35,13 +39,21 @@ const disableSourceMaps = trueEnv.includes(
);

if (disableSourceMaps) {
console.info(
`${pc.green(
console.warn(
`${pc.yellow(
'notice'
)}- Sourcemaps generation have been disabled through NEXT_DISABLE_SOURCEMAPS`
);
}

if (NEXTJS_SENTRY_DEBUG) {
console.warn(
`${pc.yellow(
'notice'
)}- Build won't use sentry treeshaking (NEXTJS_SENTRY_DEBUG)`
);
}

// Tell webpack to compile those packages
// @link https://www.npmjs.com/package/next-transpile-modules
const tmModules = [
Expand Down Expand Up @@ -109,7 +121,7 @@ const nextConfig = {
experimental: {
// Still buggy as of nextjs 12.1.5
/**
emotion: {
emotion: {
sourceMap: process.env.NODE_ENV === 'development',
autoLabel: 'dev-only',
// Allowed values: `[local]` `[filename]` and `[dirname]`
Expand All @@ -119,7 +131,7 @@ const nextConfig = {
// For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.
labelFormat: '[local]',
},
*/
*/
// React 18
// @link https://nextjs.org/docs/advanced-features/react-18
reactRoot: true,
Expand Down Expand Up @@ -183,10 +195,19 @@ const nextConfig = {
},
*/

webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
// @link https://github.com/vercel/next.js/issues/36514#issuecomment-1112074589
config.resolve.fallback = { ...config.resolve.fallback, fs: false };
webpack: (config, { webpack, isServer }) => {
if (!isServer) {
// Fixes npm packages that depend on `fs` module
// @link https://github.com/vercel/next.js/issues/36514#issuecomment-1112074589
config.resolve.fallback = { ...config.resolve.fallback, fs: false };
}

// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/
config.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: NEXTJS_SENTRY_DEBUG,
})
);

config.module.rules.push({
test: /\.svg$/,
Expand Down

3 comments on commit daa1516

@vercel
Copy link

@vercel vercel bot commented on daa1516 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-remix-app – ./apps/remix-app

monorepo-remix-app-belgattitude.vercel.app
monorepo-remix-app-git-main-belgattitude.vercel.app
monorepo-remix-app.vercel.app

@vercel
Copy link

@vercel vercel bot commented on daa1516 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-nextjs-app – ./apps/nextjs-app

monorepo-nextjs-app-git-main-belgattitude.vercel.app
monorepo-nextjs-app-belgattitude.vercel.app
monorepo-nextjs-app.vercel.app

@vercel
Copy link

@vercel vercel bot commented on daa1516 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

monorepo-vite-app – ./apps/vite-app

monorepo-vite-app-belgattitude.vercel.app
monorepo-vite-app.vercel.app
monorepo-vite-app-git-main-belgattitude.vercel.app

Please sign in to comment.