Skip to content

Commit 2e108da

Browse files
added namespace and outputTarget, new options in package.json
1 parent 0bcdbae commit 2e108da

File tree

10 files changed

+63
-22
lines changed

10 files changed

+63
-22
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
"private": true,
44
"version": "0.0.1",
55
"description": "Stencil App Starter",
6+
"main": "dist/index.cjs.js",
7+
"module": "dist/index.mjs",
8+
"collection": "dist/collection/collection-manifest.json",
9+
"types": "dist/types/index.d.ts",
10+
"files": [
11+
"dist/",
12+
"loader/"
13+
],
614
"scripts": {
715
"build": "stencil build",
816
"start": "stencil build --dev --watch --serve",

src/assets/images/app-starter1.png

120 KB
Loading

src/assets/images/app-starter2.png

70.4 KB
Loading

src/components/app-home-page/app-home-page.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ describe('app-home-page', () => {
1414
await page.setContent('<app-home-page></app-home-page>');
1515

1616
const element = await page.find('app-home-page >>> button');
17-
expect(element.textContent).toEqual('Profile page');
17+
expect(element.textContent).toEqual('Profile Page');
1818
});
1919
});

src/components/app-home-page/app-home-page.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,41 @@ import { Router } from "../..";
88
})
99
export class AppHome {
1010
render() {
11-
return (
11+
// Dynamically resolve the path to the image file
12+
const imagePath1 = new URL('../../assets/images/app-starter1.png', import.meta.url).href;
13+
const imagePath2 = new URL('../../assets/images/app-starter2.png', import.meta.url).href;
14+
return (
1215
<div class="app-home-page">
1316
<p>
1417
Welcome to the Stencil App Starter. You can use this starter to build entire apps all with web components using Stencil! Check out our docs on{' '}
1518
<a href="https://stenciljs.com">stenciljs.com</a> to get started.
1619
</p>
1720
<div>
21+
<h1>Steps to create Stencil Web App</h1>
22+
<h1>Start by npm init stencil and then choose 2nd option</h1>
23+
<img
24+
src={imagePath1}
25+
style={{
26+
width: '100%',
27+
height: '250px',
28+
}}
29+
loading="lazy"
30+
/>
31+
<img
32+
src={imagePath2}
33+
style={{
34+
width: '100%',
35+
height: '250px',
36+
}}
37+
loading="lazy"
38+
/>
1839
<h1>Pages</h1>
1940
</div>
41+
<button
42+
onClick={() => Router.push('/profile/sanjeet')}
43+
>
44+
Profile Page
45+
</button>
2046
<button
2147
onClick={() => Router.push('/web-components')}
2248
>
@@ -27,11 +53,6 @@ export class AppHome {
2753
>
2854
Posts dashboard
2955
</button>
30-
<button
31-
onClick={() => Router.push('/profile/sanjeet')}
32-
>
33-
Profile Page
34-
</button>
3556
</div>
3657
);
3758
}

src/components/posts-dashboard/posts-dashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Component,State, h } from '@stencil/core';
55
styleUrl: 'posts-dashboard.css',
66
shadow: true,
77
})
8-
export class AppHeader {
8+
export class PostsDashboard {
99
@State() posts: Array<{ id: number; title: string; body: string }> = [];
1010
// Fetch posts data when the component loads- sample API
1111
async componentWillLoad() {

src/components/posts-dashboard/test/posts-dashboard.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { newSpecPage } from '@stencil/core/testing';
2-
import { AppHeader } from '../posts-dashboard';
2+
import { PostsDashboard } from '../posts-dashboard';
33

44
describe('posts-dashboard', () => {
55
it('renders', async () => {
66
const page = await newSpecPage({
7-
components: [AppHeader],
7+
components: [PostsDashboard],
88
html: `<posts-dashboard></posts-dashboard>`,
99
});
1010
expect(page.root).toEqualHtml(`

src/components/web-components/web-components.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, h } from '@stencil/core';
22
import { defineCustomElements } from 'stenciljs-components/loader';
3+
34
@Component({
45
tag: 'web-components',
56
styleUrl: 'web-components.css',
@@ -21,8 +22,18 @@ export class WebComponents {
2122

2223
// Example: Initialize a library
2324
private initializeLibrary() {
24-
// Initialize the custom elements
25-
defineCustomElements();
25+
// Wrap the function to log the registration
26+
const defineWithLog = (win: any) => {
27+
defineCustomElements(win);
28+
29+
console.log('Registered Custom Elements:');
30+
['my-card', 'my-rich-text-editor'].forEach((tagName) => {
31+
console.log(`${tagName}:`, customElements.get(tagName));
32+
});
33+
};
34+
35+
// Use the modified version
36+
defineWithLog(window);
2637
}
2738
render() {
2839
return (

src/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<meta name="apple-mobile-web-app-capable" content="yes">
1010
<meta http-equiv="x-ua-compatible" content="IE=Edge">
1111

12-
<script type="module" src="/build/app.esm.js"></script>
13-
<script nomodule src="/build/app.js"></script>
14-
<link href="/build/app.css" rel="stylesheet">
12+
<script type="module" src="/build/myapp.esm.js"></script>
13+
<script nomodule src="/build/myapp.js"></script>
14+
<link href="/build/myapp.css" rel="stylesheet">
1515

1616
<link rel="apple-touch-icon" href="/assets/icon/icon.png">
1717
<link rel="icon" type="image/x-icon" href="/assets/icon/favicon.ico">

stencil.config.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ export const config: Config = {
66
globalStyle: 'src/global/app.css',
77
globalScript: 'src/global/app.ts',
88
taskQueue: 'async',
9-
// namespace: 'myapp',
9+
namespace: 'myapp',
1010
outputTargets: [
1111
{
12-
type: 'www',
12+
type: 'dist', // For reusable components,Required for `defineCustomElements`
13+
esmLoaderPath: '../loader',
14+
},
15+
{
16+
type: 'www', // Optional, for a local development server
1317
// comment the following line to disable service workers in production
1418
serviceWorker: null,
15-
baseUrl: 'https://myapp.local/',
19+
// baseUrl: 'https://myapp.local/',
1620
// baseUrl:'/build/', like in fluid it opens to localhost:3333/fluid/
1721
},
18-
// {
19-
// type: 'dist', // For reusable components
20-
// esmLoaderPath: '../loader',
21-
// },
22+
2223
],
2324
};

0 commit comments

Comments
 (0)