Stencil: In development, being able to implement multiple html pages to test components

Created on 18 Oct 2019  ยท  1Comment  ยท  Source: ionic-team/stencil

Stencil version:

@stencil/[email protected] 

I'm submitting a:
[ ] bug report
[x] 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:
While developing component, there's only src/index.html available to test my components.

Expected behavior:
I'm looking for a way to create different pages while developing components, instead of using only src/index.html. Ideally, an html page per component.

I don't want to create components as a page to simulate pages, because they would be exported in the final dist folder, which I want to keep clean and component focus only.

The documentation doesn't explicitly detail the best way of doing so. The Stencil Style Guide page https://stenciljs.com/docs/style-guide describes a file structure to adopt, and I can see a test folder with an html page:

โ”œโ”€โ”€ card
โ”‚   โ”œโ”€โ”€ card.ios.css
โ”‚   โ”œโ”€โ”€ card.md.css
โ”‚   โ”œโ”€โ”€ card.css
โ”‚   โ”œโ”€โ”€ card.tsx
โ”‚   โ””โ”€โ”€ test
โ”‚       โ””โ”€โ”€ basic
โ”‚           โ”œโ”€โ”€ e2e.js
โ”‚           โ””โ”€โ”€ index.html

How can I make the dev-server serving the card/test/basic/index.html ?

Thanks!

triage

Most helpful comment

Never mind, I found a solution. You can create the architecture you want, but it's better to create it this way:

โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ components
โ”‚   โ””โ”€โ”€ pages
โ”‚       โ””โ”€โ”€ my-component
โ”‚           โ”œโ”€โ”€ index.html
โ”‚       โ””โ”€โ”€ my-second-component
โ”‚           โ”œโ”€โ”€ index.html
โ”‚     

In stencil.config.ts, add a copy property in the www target that copies the /pages folder into the www folder on build

outputTargets: [
    ...
    {
      type: 'www',
      serviceWorker: null, // disable service workers
      copy: [
        ...
        { src: 'pages' },
      ],
    }
  ]

Now, on build or dev, you can access the html pages you created in the pages folder. Here for instance, http://localhost:3333/pages/my-component.

Thanks!

>All comments

Never mind, I found a solution. You can create the architecture you want, but it's better to create it this way:

โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ components
โ”‚   โ””โ”€โ”€ pages
โ”‚       โ””โ”€โ”€ my-component
โ”‚           โ”œโ”€โ”€ index.html
โ”‚       โ””โ”€โ”€ my-second-component
โ”‚           โ”œโ”€โ”€ index.html
โ”‚     

In stencil.config.ts, add a copy property in the www target that copies the /pages folder into the www folder on build

outputTargets: [
    ...
    {
      type: 'www',
      serviceWorker: null, // disable service workers
      copy: [
        ...
        { src: 'pages' },
      ],
    }
  ]

Now, on build or dev, you can access the html pages you created in the pages folder. Here for instance, http://localhost:3333/pages/my-component.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjorasch picture cjorasch  ยท  3Comments

joewoodhouse picture joewoodhouse  ยท  3Comments

glemiere picture glemiere  ยท  3Comments

romulocintra picture romulocintra  ยท  3Comments

MatanYadaev picture MatanYadaev  ยท  3Comments