When I'm writing an Angular library compatible with SystemJS and Webpack, sometimes, there are some different results after the loading page. To patch a component and errase differences, I'm trying to find the right way to detect if it's a webpack environnement or a systemJS one inside the component.
One hacky solution : In webpack, one attribute is added like "_ngcontent-xxx-n" for each component so there is a difference of length of attributes between a component loaded by systemJS and one loaded by Webpack, so I did this :
( this.elHTML.attributes[x] === undefined ) ? //Code for webpack : //Code for SystemJS;
But the problem is the length of attributes can change and make future bugs so is there a better solution, please ?
I found a right solution. The Property to check is on the window javascript object.
( window.hasOwnProperty("SystemJS") ) ? //Code for SystemJS : //Code for Webpack;