Skip to content

Commit c73343c

Browse files
authored
feat(angular): Add Angular CLI + Webpack Plugin sourcemaps upload guide (#6404)
Add a new source maps upload guide to our Angular SDK docs: Users can make use of the Angular CLI and the Sentry Webpack plugin to upload source maps. This requires a custom Angular builder. Changes: - Add a tutorial for Angular CLI + Webpack plugin - Add Angular-specific source maps overview and source maps uploading index page - Let the PageGrid component accept an exclude prop to exclude certain entries from being displayed Otherwise we show source maps upload option twice, once in the "recommended" section and once in the "other options" section of the uploading index page.
1 parent ece0c53 commit c73343c

File tree

4 files changed

+188
-6
lines changed

4 files changed

+188
-6
lines changed

src/components/pageGrid.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import { sortPages } from "~src/utils";
77

88
const query = graphql`
99
query PageGridQuery {
10-
allSitePage(
11-
filter: {
12-
context: { draft: { ne: true } }
13-
}
14-
) {
10+
allSitePage(filter: { context: { draft: { ne: true } } }) {
1511
nodes {
1612
path
1713
context {
@@ -27,9 +23,14 @@ const query = graphql`
2723
type Props = {
2824
nextPages: boolean;
2925
header?: string;
26+
/**
27+
* A list of pages to exclude from the grid.
28+
* Specify the file name of the page, for example, "index" for "index.mdx"
29+
*/
30+
exclude?: string[];
3031
};
3132

32-
export default ({ nextPages = false, header }: Props): JSX.Element => {
33+
export default ({ nextPages = false, header, exclude }: Props): JSX.Element => {
3334
const data = useStaticQuery(query);
3435
const location = useLocation();
3536

@@ -55,6 +56,12 @@ export default ({ nextPages = false, header }: Props): JSX.Element => {
5556
matches = matches.filter(n => n.path !== currentPath);
5657
}
5758

59+
if (exclude && exclude.length) {
60+
exclude.forEach(e => {
61+
matches = matches.filter(n => !n.path.endsWith(`${e}/`));
62+
});
63+
}
64+
5865
if (!matches.length) return null;
5966

6067
return (
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Uploading Source Maps in an Angular project
2+
3+
Sentry uses [releases](/product/releases/) to match the correct source maps to your events.
4+
This page explains how to generate source maps, set releases, and upload source maps to Sentry either manually or automatically when bundling your Angular app.
5+
6+
### Generating Source Maps
7+
8+
To generate source maps, you need to add the `sourceMap` option to your `angular.json` build configuration:
9+
10+
```json {filename:angular.json}
11+
{
12+
// ...
13+
"projects": {
14+
"my-app": {
15+
"architect": {
16+
"build": {
17+
"configurations": {
18+
"production": {
19+
"sourceMap": {
20+
"scripts": true
21+
}
22+
}
23+
}
24+
}
25+
}
26+
}
27+
}
28+
}
29+
```
30+
31+
### Two Ways to Upload Source Maps
32+
33+
You can either set releases and upload source maps automatically using the Angular CLI, or upload source maps manually using the Sentry-CLI.
34+
35+
- [**Angular CLI and Sentry Webpack Plugin**](./uploading/angular-webpack/) <br/>
36+
Use the Angular CLI, a custom Angular builder and the Sentry Webpack plugin to set releases and upload source maps automatically when running `ng build`.
37+
- [**Sentry CLI**](./uploading/cli/)<br/>
38+
Upload source maps manually using the Sentry-CLI.
39+
40+
Take a look at this [guide for further options to upload source maps](./uploading/).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
To upload your Angular project's source maps to Sentry, we recommend one of these two options:
2+
3+
- [**Angular CLI and Sentry Webpack Plugin**](./angular-webpack/) <br/>
4+
Use the Angular CLI, a custom Angular builder and the Sentry Webpack plugin to set releases and upload source maps automatically when running `ng build`.
5+
- [**Sentry CLI**](./cli/)<br/>
6+
Upload source maps manually using Sentry-CLI.
7+
8+
These options work well with Angular projects out of the box. For other bundlers or more advanced projects and configurations, take a look at the following guides and options for uploading sourcemaps:
9+
10+
<PageGrid exclude={['angular-webpack', 'cli']}/>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: Angular CLI
3+
description: "Upload your source maps using the Angular CLI, a custom Angular builder and the Sentry Webpack plugin."
4+
sidebar_order: 0
5+
supported:
6+
- javascript.angular
7+
---
8+
9+
You can use the Angular CLI together with our Sentry Webpack plugin to automatically create releases and upload source maps to Sentry when building your app (with `ng build`, for example).
10+
Due to Angular's closed build system, to register the Webpack plugin, you'll first need to configure a custom builder.
11+
In the end, you'll be able to automatically upload source maps whenever you're creating a production build of your app.
12+
13+
<Alert level="warning">
14+
15+
Before you start configuring the source maps upload, make sure that you're [generating source maps](../../.#generating-source-maps) in your Angular project.
16+
17+
</Alert>
18+
19+
## Install
20+
21+
Install the custom Webpack builder for Angular and the Sentry Webpack plugin:
22+
23+
```shell {tabTitle:npm}
24+
npm install --save-dev @angular-builders/custom-webpack @sentry/webpack-plugin
25+
```
26+
27+
```shell {tabTitle:yarn}
28+
yarn add --dev @angular-builders/custom-webpack @sentry/webpack-plugin
29+
```
30+
31+
## Configure
32+
33+
With these packages installed, configure your app to upload source maps in three steps:
34+
35+
### 1. Set up custom Angular builder
36+
37+
In your `angular.json`, replace the default builder (`@angular-devkit/build-angular`) with `@angular-builders/custom-webpack`:
38+
39+
```javascript {filename:angular.json}
40+
{
41+
"projects": {
42+
"my-project": {
43+
"architect": {
44+
"build": {
45+
"builder": "@angular-builders/custom-webpack:browser",
46+
"options": {
47+
"customWebpackConfig": {
48+
"path": "./webpack.config.js"
49+
},
50+
// ... other options
51+
},
52+
// ... other options
53+
},
54+
// ... other options
55+
},
56+
// ... other options
57+
}
58+
}
59+
}
60+
```
61+
62+
<Alert>
63+
64+
This configuration has no effect on your development server if you're running `ng serve`.
65+
Only `ng build` is configured to use the custom builder and the Webpack plugin.
66+
If you're using an Angular version below 13, only `ng build --prod` will leverage the custom builder.
67+
68+
</Alert>
69+
70+
### 2. Register the Sentry Webpack Plugin
71+
72+
Register the Sentry Webpack plugin in your `webpack.config.js`:
73+
74+
```javascript {filename:webpack.config.js}
75+
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
76+
77+
module.exports = {
78+
// ... other config above ...
79+
80+
devtool: "source-map", // Source map generation must be turned on
81+
plugins: [
82+
new SentryWebpackPlugin({
83+
org: "___ORG_SLUG___",
84+
project: "___PROJECT_SLUG___",
85+
86+
// Auth tokens can be obtained from https://sentry.io/settings/account/api/auth-tokens/
87+
// and need the `project:releases` and `org:read` scopes
88+
authToken: process.env.SENTRY_AUTH_TOKEN,
89+
90+
// Specify the directory containing build artifacts
91+
// By default, Angular emits build files in the `dist` directory but your
92+
// configuration may vary
93+
include: "./dist/my-project",
94+
95+
// Optionally uncomment the line below to override automatic release name detection
96+
// release: process.env.RELEASE,
97+
}),
98+
],
99+
};
100+
```
101+
102+
Learn more about configuring the plugin in our [Sentry Webpack Plugin documentation](https://github.com/getsentry/sentry-webpack-plugin).
103+
104+
### 3. Upload
105+
106+
To upload the source maps, build your Angular application:
107+
108+
```bash
109+
ng build # add --prod for Angular versions below 13
110+
```
111+
112+
### Releases
113+
114+
The Sentry Webpack plugin will automatically inject a release value into the SDK, so you should either omit the `release` option from `Sentry.init` or make sure `Sentry.init`'s `release` option matches the plugin's `release` option exactly:
115+
116+
```javascript
117+
Sentry.init({
118+
dsn: "___PUBLIC_DSN___",
119+
120+
// When using the plugin, either remove the `release`` property here entirely or
121+
// make sure that the plugin's release option and the Sentry.init()'s release
122+
// option match exactly.
123+
// release: "my-example-release-1"
124+
});
125+
```

0 commit comments

Comments
 (0)