Giter Club home page Giter Club logo

Comments (9)

donskov avatar donskov commented on September 26, 2024 2

@bjesuiter Please try to add import to src/index.ts:

export { Components } from './components';
import '@stencil/router';
import 'ionicons';

from stencil-site.

splitinfinities avatar splitinfinities commented on September 26, 2024 1

Noted that we should improve the documentation around where to import other stencil built web components - importing them from within the src/index.ts is the correct way to do this.

import 'ionicons';

from stencil-site.

miqmago avatar miqmago commented on September 26, 2024 1

I've created a new stencil component and tried the following the steps:

  1. Install ionicons: npm i ionicons:

    "@ionic/core": "^6.0.4",
    "@stencil/core": "^2.13.0",
    "ionicons": "^6.0.1",
  2. Add import 'ionicons'; in src/index.ts:

    import 'ionicons';
    import '@ionic/core';
    
    export { Components, JSX } from './components';
  3. Use ion-icon in my-component:

    render() {
        return (
            <ion-buttons>
                <ion-button>
                    <ion-icon slot="icon-only" name="remove-outline" />
                </ion-button>
            </ion-buttons>
        );
  4. Build the component npm run build

  5. npm link the component into another project with only an index.html webpage:

    <!DOCTYPE html>
    <html>
    <head>
        <script type="module" src="/node_modules/my-component/dist/my-component/my-component.esm.js"></script>
    </head>
    <body>
        <my-component />
    </body>
    </html>
  6. live-serve the whole folder

  7. Access to index.html. The html seems to be rendered, but the icon itself is missing (no icon shown inside ion-icon):

    Captura de Pantalla 2022-01-30 a les 15 59 40

    Empty icons:

    Captura de Pantalla 2022-01-30 a les 16 03 59

EDIT
This is quite strange, the published npm version at pdf-component works fine, but I was affraid to publish something that was not working at all. I've tried the local files of published version in via linked node_modules and it still does not work.

from stencil-site.

bjesuiter avatar bjesuiter commented on September 26, 2024

Ok, for some reason it does work now when adding import 'ionicons'; to my byc-region.tsx component file without having the script tag in index.html for the ionicons.js import from unpkg.
(this one: <!-- <script src="https://unpkg.com/[email protected]/dist/ionicons.js"></script>-->)'

Note, that I did not have to add it to index.ts.

To avoid my test being flawed by the browser cache, instructed ion-icon to load the md-aperture and md-airplane icons which I did not load at all before.

I also did compile it and imported it as Webcomponent into another project and it works.

A little question for understanding:
Would the dependency to ionicons get distributed along with my component, when imported in my src/index.ts, as the import in my own component does ?

@donskov Thanks for your help anyway! :)

But anyway, this import 'some-other stencil-package'; Syntax should be described in the documentation.
Could you guys add a page with a name something like 'Using other Webcomponents for your stencil component' under the Components Part of the Documentation Website?
https://stenciljs.com/docs/decorators

from stencil-site.

mmsharkey avatar mmsharkey commented on September 26, 2024

I've tried all the above mentioned solutions using stencil and ionic to create a component and then exporting my component into a create-react-app and the icons will not show. I used a fresh stencil starter project and a fresh create-react-app project.

The script tag to add into the index.html is fickle (sometimes it works, and other times it doesn't.)

From my understanding, I shouldn't even need the script tag since ion icons should come included with ionic. Can someone please advise?

from stencil-site.

avrghz avatar avrghz commented on September 26, 2024

Is there any update on this issue? I am also facing the same issue. In development bundle the icon shows up, but not in the production bundle.

from stencil-site.

nagashimam avatar nagashimam commented on September 26, 2024

@avrghz
I know it's late, but better than nothing...

How do you serve your production bundle? In my case, I was using VSCode's Live Server extension, which for some reason injects script tag with svg tag. And ion-icon doesn't accept that as the docs says. https://ionicons.com/usage#custom_icons

from stencil-site.

nathan2slime avatar nathan2slime commented on September 26, 2024

Same thing happened here, I added import 'ionicons'; in src/index.ts, but ion-icon doesn't render an icon, just a div

from stencil-site.

rramsey avatar rramsey commented on September 26, 2024

And here it is late 2024 and there are still some things to work out in the documentation. For example, if you are adding ionicons to a stencil component, do you need to run npm install --save @ionic/core as well and import that into your index.ts file? Yes, yes you do. Luckily for me miqmago documented it here.

That should be documented somewhere. It probably is and I missed it. But if @ionic/core is required by ionicons, shouldn't that be listed in ionicons' package.json and automatically installed like other dependencies?

I installed both @ionic/core and ionicons, imported both in my index.ts, and imported both into my component's tsx file. Stopped the server and did npm run build and npm run start and the icon finally appeared.

Too bad you can't do something nice and simple like style="color: blue;" in an ion-icon element, because that would be easy.

from stencil-site.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.