It appears that Angular Universal ignores the list of global scripts defined in angular.json
. Is there something I'm doing incorrectly, or is this a bug worth filing?
To reproduce, clone the universal-starter
repo.
In src/app/app.component.ts
add this function declaration:
declare function globalFunction(): void;
And call it in the constructor:
export class AppComponent {
constructor() { globalFunction(); }
}
Next, create the file src/javascripts.js
and add this to it:
function globalFunction() {
console.log("Hello, world!");
}
Finally, edit angular.json
and add the new JavaScript file to the scripts
array:
"scripts": [
"src/javascripts.js"
]
Run ng serve
and visit http://localhost:4200
...you should see "Hello, world!" printed to the JavaScript console.
Now build the Universal app using npm run build:prerender
...you should see the error: ReferenceError: globalFunction is not defined
.