Skip to content

Commit 23bbb11

Browse files
loading stenciljs component via URL instead of installation
1 parent 48dbf31 commit 23bbb11

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/components/app-root/app-root.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, h } from '@stencil/core';
33
import { Router } from "../../"; //in index.ts its already there so no need to again do const Router = createRouter();
44

55
import { Route, match } from "stencil-router-v2";
6-
6+
//https://www.npmjs.com/package/stencil-router-v2
77
@Component({
88
tag: 'app-root',
99
styleUrl: 'app-root.css',

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, h } from '@stencil/core';
2-
2+
//import { defineCustomElements } from 'stenciljs-components/loader';
33
@Component({
44
tag: 'web-components',
55
styleUrl: 'web-components.css',
@@ -9,14 +9,25 @@ export class WebComponents {
99
/**
1010
* Called once just after the component is first connected to the DOM.
1111
*/
12-
12+
componentDidLoad() {
13+
// async function initializeStencilComponents() {
14+
// console.log('Initializing StencilJS components...');
15+
// await defineCustomElements(window, {
16+
// resourcesUrl: './build/', // Adjust based on your deployment structure
17+
// }); // Pass the global `window` object
18+
// console.log('StencilJS components initialized.');
19+
// }
20+
// initializeStencilComponents();
21+
//defineCustomElements();
22+
23+
}
1324
render() {
1425
return (
1526
<div>
16-
<p>URL of this component library:<a href="https://sanjeetkumaritoutlook.github.io/stenciljs-components/" target="_blank">Visit</a></p>
17-
<p>by Default,Stencil Web app creates three components:app-root, app-home, app-profile with Routung from "stencil-router-v2" pre-installed </p>
27+
<p>Below components in this page are rendering from <a href="https://www.npmjs.com/package/stenciljs-components" target="_blank"><strong>stenciljs-components npm package</strong></a></p>
28+
<p>Sandbox page of this component library:<a href="https://sanjeetkumaritoutlook.github.io/stenciljs-components/" target="_blank">Visit</a></p>
29+
<p>By Default,Stencil Web app creates three components:app-root, app-home, app-profile with Routung from "stencil-router-v2" pre-installed </p>
1830
<p>To avoid conflict with npm package (stenciljs-components) which has similar naming components, renamed the component in this web app to app-home-page and app-profile-page respectively</p>
19-
2031
<my-rich-text-editor initial-value="this is initial value" placeholder="angular placeholder"></my-rich-text-editor>
2132

2233
<my-card user-name="CodingLocker"></my-card>

src/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<script type="module" src="/build/myapp.esm.js"></script>
1313
<script nomodule src="/build/myapp.js"></script>
1414
<link href="/build/myapp.css" rel="stylesheet">
15-
15+
<script type="module" src="https://sanjeetkumaritoutlook.github.io/stenciljs-components/build/stenciljs-components.esm.js"></script>
16+
<script nomodule src="https://sanjeetkumaritoutlook.github.io/stenciljs-components/build/stenciljs-components.js"></script>
1617
<link rel="apple-touch-icon" href="/assets/icon/icon.png">
1718
<link rel="icon" type="image/x-icon" href="/assets/icon/favicon.ico">
1819
<link rel="manifest" href="/manifest.json">

src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ import { createRouter } from 'stencil-router-v2';
33
export { Components, JSX } from './components';
44

55
export const Router = createRouter();
6-
import { defineCustomElements } from 'stenciljs-components/loader';
7-
async function initializeStencilComponents() {
8-
console.log('Initializing StencilJS components...');
9-
await defineCustomElements(window, {
10-
resourcesUrl: './build/', // Adjust based on your deployment structure
11-
}); // Pass the global `window` object
12-
console.log('StencilJS components initialized.');
13-
}
14-
initializeStencilComponents();
6+
157

168
import { fluidEnvironments } from '../fluid';
179
const script = document.createElement('script');

0 commit comments

Comments
 (0)