Hi @gillestasse!
To create new components in StencilJS:
git clone https://github.com/ionic-team/stencil-app-starter app-name
cd app-name
git remote rm origin
npm install
npm start
Stencil components are created by adding a new file with a .tsx extension.
Modify existing project code or create your new component. Follow the official documentation if you have any questions.
Once you have tested build for production with
npm run build
This will generate a minified distribution of your stencil component in build folder.
Integrate Web Component in Ionic
Steps
- In your Ionic project copy web componet build folder in src/assets/lib (for example).
- In src/app/app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA } from ‘@angular/core’;
Add schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
Example
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { CounterWrapperComponent } from '../components/counter-wrapper/counter-wrapper';
@NgModule({
declarations: [
MyApp,
HomePage,
CounterWrapperComponent
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule {}
- Use your web component in page (for example home.ts)
<ion-header>
<ion-navbar>
<ion-title>
Stencil WC Ionic
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<counter-wrapper>
<my-counter start="10" min="0" max="100" step="5"></my-counter>
</counter-wrapper>
</ion-content>