Skip to content

Commit

Permalink
docs(examples/angular): Fix CSP issues with inline event handler scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
PSanetra committed Aug 7, 2024
1 parent 01e47f6 commit 68908e0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
20 changes: 20 additions & 0 deletions examples/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ This is a small Angular example app, which includes a `spa_config.js` to configu
3. Declare `spaConfig` in the `window` object via the TypeScript definition file `/src/@types/spa_config.d.ts`
4. Add `<script src="./spa_config.js"></script>` to `index.html`
5. Add a `/config/default.yaml` configuration file to the image, which allows 'unsafe-inline' styles. (See `default-config.yaml`, [#angular/26152](https://github.com/angular/angular/issues/26152))
6. [Disable inline event handler script for styles.](https://github.com/angular/angular-cli/issues/20864#issuecomment-1165769416):
* ```json
{
"...": "...",
"configurations": {
"production": {
"...": "...",
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
}
},
"...": "..."
}
}
```

## Build Dockerfile

Expand Down
13 changes: 10 additions & 3 deletions examples/angular/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"src/spa_config.js"
],
"styles": [
"src/styles.sass"
"src/styles.scss"
],
"scripts": []
},
Expand All @@ -46,7 +46,14 @@
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
},
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
Expand Down Expand Up @@ -96,7 +103,7 @@
"src/assets"
],
"styles": [
"src/styles.sass"
"src/styles.scss"
],
"scripts": []
}
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions examples/angular/src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
margin-bottom: 10px;
}
2 changes: 1 addition & 1 deletion examples/angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.sass']
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = window.spaConfig.appTitle;
Expand Down
1 change: 0 additions & 1 deletion examples/angular/src/styles.sass

This file was deleted.

3 changes: 3 additions & 0 deletions examples/angular/src/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
margin: 10px;
}

0 comments on commit 68908e0

Please sign in to comment.