The PWABuilder starter comes with Shoelace, which has a library of icons, but they don't seem to work out of the box:
import '@shoelace-style/shoelace/dist/components/icon/icon.js';
@customElement('app-index')
export class AppIndex extends LitElement {
// ...
render() {
return html```
<sl-icon name="0-circle-fill"></sl-icon>
```;
}
shows an empty icon.
The Shoelace doc mentions the need to configure the bundler and basePath
but doesn't come with an example of Vite config.
The icons in question are all bundled in the Shoelace package in node_modules: node_modules/@shoelace-style/shoelace/dist/assets/
, so I guess it's just a matter of configuring Vite to make those accessible as public assets, but it's really not obvious how.
How to make Shoelace icons work with Vite? More generally, how to make node_modules assets accessible to a Vite-bundled app?
Found a way using the
vite-plugin-static-copy
plugin:Then in
./vite.config.ts
, add the followingviteStaticCopy
entry at the top of theplugins:
array:This will make your icons available in
/shoelace/assets/icons/
.Then in your JS code, e.g. in
src/app-index.js
, add:This will tell Shoelace to look for those assets in
/shoelace
.