I have created a web component using custom elements with Angular 8. Part of the component is to show some custom icons (developed and packaged as a different app). I have included the package of the custom icons in the package.json
file of the component:
"dependencies": {
"@somelibrary/icons": "1.0.34"
}
I gets correctly installed in the node modules. In the angular.json
file I include the css file in the styles:
"styles": [
"src/styles.css",
"node_modules/@somelibrary/icons/css/fontface.css"
],
Where the fontface.css
file specifies the urls of the custom font files with font-face:
@font-face {
font-family: "my-fonts";
src:url('../fonts/my-fonts.woff2') format('woff2'),
url('../fonts/my-fonts.woff') format('woff'),
url('../fonts/my-fonts.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
I then build the custom web component and concatenate all created js files into one, to be used as a standalone component.
cat dist/lib/runtime.js dist/lib/polyfills.js dist/lib/scripts.js dist/lib/main.js > dist/myComponent.js
The issue here is that when I use the final produced javascript file (include it in a simple index.html page), the tff and woff files are not included, so I end up just seeing the placeholder of the icon.
I have tried including the font files during the built myComponent.js
file but as expected I get a syntax error.
cat dist/lib/runtime.js dist/lib/polyfills.js dist/lib/scripts.js dist/lib/main.js dist/lib/my-fonts.ttf> dist/myComponent.js
I have seen answers like this but the goal is a portable component and also because the fonts are external I cannot move them to the assets folder as they may change over time.
I have also explored options from this thread, I cannot externalize assets (since they come from a package) and the url-loader used for ttf and wof files does not work.
Has anyone ever tried something similar? How can a web component composed of a single javascript file include external fonts that are shown in a standalone application.