-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore: Add bundle analysis package #11379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,15 @@ | ||
# Bundle Analyzer Scenarios | ||
|
||
This repository contains a set of scenarios to check the SDK against webpack bundle analyzer. | ||
|
||
You can run the scenarios by running `yarn analyze` and selecting the scenario you want to run. | ||
|
||
If you want to have more granular analysis of modules, you can build the SDK packages with with `preserveModules` set to | ||
`true`. You can do this via the `SENTRY_BUILD_PRESERVE_MODULES`. | ||
|
||
```bash | ||
SENTRY_BUILD_PRESERVE_MODULES=true yarn build | ||
``` | ||
|
||
Please note that `preserveModules` has different behaviour with regards to tree-shaking, so you will get different total | ||
bundle size results. |
5 changes: 5 additions & 0 deletions
5
dev-packages/bundle-analyzer-scenarios/browser-basic/index.js
This file contains hidden or 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,5 @@ | ||
import { init } from '@sentry/browser'; | ||
|
||
init({ | ||
dsn: 'https://[email protected]/0000000', | ||
}); |
4 changes: 4 additions & 0 deletions
4
dev-packages/bundle-analyzer-scenarios/browser-basic/package.json
This file contains hidden or 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,4 @@ | ||
{ | ||
"type": "module", | ||
"main": "index.js" | ||
} |
This file contains hidden or 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,23 @@ | ||
{ | ||
"name": "@sentry-internal/bundle-analyzer-scenarios", | ||
"version": "8.0.0-alpha.7", | ||
"description": "Scenarios to test bundle analysis with", | ||
"repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/dev-packages/bundle-analyzer-scenarios", | ||
"author": "Sentry", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"html-webpack-plugin": "^5.5.0", | ||
"webpack": "^5.76.0", | ||
"webpack-bundle-analyzer": "^4.5.0", | ||
"inquirer": "^8.2.0" | ||
}, | ||
"scripts": { | ||
"analyze": "node webpack.cjs" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"type": "module" | ||
} |
This file contains hidden or 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,83 @@ | ||
const path = require('path'); | ||
const { promises } = require('fs'); | ||
|
||
const inquirer = require('inquirer'); | ||
const webpack = require('webpack'); | ||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
async function init() { | ||
const scenarios = await getScenariosFromDirectories(); | ||
|
||
const answers = await inquirer.prompt([ | ||
{ | ||
type: 'rawlist', | ||
name: 'scenario', | ||
message: 'Which scenario you want to run?', | ||
choices: scenarios, | ||
pageSize: scenarios.length, | ||
loop: false, | ||
}, | ||
]); | ||
|
||
console.log(`Bundling scenario: ${answers.scenario}`); | ||
|
||
await runWebpack(answers.scenario); | ||
} | ||
|
||
async function runWebpack(scenario) { | ||
const alias = await generateAlias(); | ||
|
||
webpack( | ||
{ | ||
mode: 'production', | ||
entry: path.resolve(__dirname, scenario), | ||
output: { | ||
filename: 'main.js', | ||
path: path.resolve(__dirname, 'dist', scenario), | ||
}, | ||
plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static' }), new HtmlWebpackPlugin()], | ||
resolve: { | ||
alias, | ||
}, | ||
}, | ||
(err, stats) => { | ||
if (err || stats.hasErrors()) { | ||
console.log(err); | ||
} | ||
|
||
// console.log('DONE', stats); | ||
}, | ||
); | ||
} | ||
|
||
const PACKAGE_PATH = '../../packages'; | ||
|
||
/** | ||
* Generate webpack aliases based on packages in monorepo | ||
* Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless', | ||
*/ | ||
async function generateAlias() { | ||
const dirents = await promises.readdir(PACKAGE_PATH); | ||
|
||
return Object.fromEntries( | ||
await Promise.all( | ||
dirents.map(async d => { | ||
const packageJSON = JSON.parse(await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json'))); | ||
return [packageJSON['name'], path.resolve(PACKAGE_PATH, d)]; | ||
}), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Generates an array of available scenarios | ||
*/ | ||
async function getScenariosFromDirectories() { | ||
const exclude = ['node_modules', 'dist', '~', 'package.json', 'yarn.lock', 'README.md', '.DS_Store', 'webpack.cjs']; | ||
|
||
const dirents = await promises.readdir(path.join(__dirname), { withFileTypes: true }); | ||
return dirents.map(dirent => dirent.name).filter(mape => !exclude.includes(mape)); | ||
} | ||
|
||
init(); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also removing codecov for now until they fix their reporting for our sdk setup.