I cannot make base Angular2 (final) application works with the following restrictive CSP.
default-src \'none\';
script-src \'self\';
style-src \'self\';
font-src
Edited answer for @angular/cli>=8.2
From this Github thread, one can use the index
property in angular.json
to control the generation of the application's HTML index:
build: {
...
"configurations": {
"production": {
"index": {
"input": "src/index.production.html",
"output": "index.html"
},
...
}
}
}
Original answer
I've found a way to have restrictive CSP on my production environment while still being able to use the JTI compliler for development.
index.production.html
to the src
folder.index.html
to that file, and add the restrictive CSP header.
angular.json
the following:build: {
...
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/index.html",
"with": "src/index.production.html"
}
],
...
}
}
}
This makes sure that when you run a production build, it will use the index.production.html
with the restrictive CSP, and when you're running it locally, you can use the JTI compiler.