現象
npm installでモジュールを追加すると下記警告がビルド時に発生しました。Warning: {tsファイル名} depends on '{nodeパッケージ名}'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
この警告を放置しておくと、ビルド成果物のサイズが不必要に大きくなってしまうようです。
対処法
angular.jsonの"build"→"options配下にallowedCommonJsDependenciesの設定を追加します。仮にnpmでhogeというパッケージがこの警告に引っ掛かっている場合は下記のような記述をします。angular.json
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"hoge"
],
...