Closed
Description
Stencil version:
@stencil/[email protected]
I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
I've created a component that essentially spits out an svg when used. So this component works well when using the test server but when the component has been built and published, it is unable to find the assets.
Expected behavior:
The expected behaviour is that the component should be able to output the icon the same way it does locally
Steps to reproduce:
Import library within Angular and try to utilize web component.
<test-icon icon="arrow-down"></test-icon>
Related code:
Component
import {
Component,
Host,
h,
State,
Prop,
Watch,
getAssetPath,
} from '@stencil/core';
import { getSvgContent } from './util';
@Component({
tag: 'test-icon',
styleUrl: 'icon.css',
assetsDir: 'svg',
shadow: true,
})
export class SmartIcons {
@Prop() icon: string;
@State() private svgContent?: string;
connectedCallback() {
this.loadIcon();
}
@Watch('icon')
loadIcon() {
const svg = `svg/test-${this.icon}.svg`;
const url = getAssetPath(svg);
if (this.icon) {
getSvgContent(url).then((content) => {
this.svgContent = content;
});
}
}
render() {
return (
<Host role="img">
{this.svgContent ? (
<div innerHTML={this.svgContent}></div>
) : (
<div></div>
)}
</Host>
);
}
}
Other information:
zone-evergreen.js:1042 GET http://localhost:4200/svg/smart-arrow-down.svg 404 (Not Found)
(anonymous) @ zone-evergreen.js:1042
getSvgContent @ smart-button_2.entry.js:18
loadIcon @ smart-button_2.entry.js:42
connectedCallback @ smart-button_2.entry.js:36
safeCall @ core-7cea914b.js:853
fireConnectedCallback @ core-7cea914b.js:1018
initializeComponent @ core-7cea914b.js:999
async function (async)
initializeComponent @ core-7cea914b.js:965
(anonymous) @ core-7cea914b.js:1044
invoke @ zone-evergreen.js:359
run @ zone-evergreen.js:124
(anonymous) @ zone-evergreen.js:855
invokeTask @ zone-evergreen.js:391
runTask @ zone-evergreen.js:168
drainMicroTaskQueue @ zone-evergreen.js:559
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:542
scheduleTask @ zone-evergreen.js:381
scheduleTask @ zone-evergreen.js:211
scheduleMicroTask @ zone-evergreen.js:231
scheduleResolveOrReject @ zone-evergreen.js:845
then @ zone-evergreen.js:955
bootstrapModule @ core.js:40599
./src/main.ts @ main.ts:14
__webpack_require__ @ bootstrap:84
0 @ main.ts:16
__webpack_require__ @ bootstrap:84
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js:1