I just run the command:
$ npx create-stencil ionic-pwa
which created a vanilla Ionic 4 PWA
with the following directory structure inside directory: src
:
.
├── assets
│ └── icon
│ ├── favicon.ico
│ └── icon.png
├── components
│ ├── app-home
│ │ ├── app-home.css
│ │ ├── app-home.spec.ts
│ │ └── app-home.tsx
│ ├── app-profile
│ │ ├── app-profile.css
│ │ ├── app-profile.spec.ts
│ │ └── app-profile.tsx
│ └── my-app
│ ├── my-app.css
│ ├── my-app.spec.ts
│ └── my-app.tsx
├── components.d.ts
├── global
│ ├── app.css
│ └── app.ts
├── helpers
│ └── utils.ts
├── index.html
├── manifest.json
└── sw.js
Then I want to create a custom component with html tag: comp-workspace
and file name: comp-workspace.js
(or something similar) that I can insert on any vanilla HTML
/Javascript
page without using any Javascript framework.
There are some things to take into consideration here:
-
component:
comp-workspace
can include the following components: {comp-gallery
,comp-artboard
,comp-text-editor
,comp-layer-stack
}. -
all above components can include standard
Ionic
components.
Please, take a look to the following diagram:
Here is the directory structure after adding my custom component: comp-workspace
and its dependencies.
.
├── assets
│ └── icon
│ ├── favicon.ico
│ └── icon.png
├── components
│ ├── app-home
│ │ ├── app-home.css
│ │ ├── app-home.spec.ts
│ │ └── app-home.tsx
│ ├── app-profile
│ │ ├── app-profile.css
│ │ ├── app-profile.spec.ts
│ │ └── app-profile.tsx
│ ├── comp-workspace
│ │ ├── comp-workspace.css
│ │ ├── comp-workspace.spec.ts
│ │ └── comp-workspace.tsx
│ ├── comp-gallery
│ │ ├── comp-gallery.css
│ │ ├── comp-gallery.spec.ts
│ │ └── comp-gallery.tsx
│ ├── comp-artboard
│ │ ├── comp-artboard.css
│ │ ├── comp-artboard.spec.ts
│ │ └── comp-artboard.tsx
│ ├── comp-text-editor
│ │ ├── comp-text-editor.css
│ │ ├── comp-text-editor.spec.ts
│ │ └── comp-text-editor.tsx
│ ├── comp-layer-stack
│ │ ├── comp-layer-stack.css
│ │ ├── comp-layer-stack.spec.ts
│ │ └── comp-layer-stack.tsx
│ └── my-app
│ ├── my-app.css
│ ├── my-app.spec.ts
│ └── my-app.tsx
├── components.d.ts
├── global
│ ├── app.css
│ └── app.ts
├── helpers
│ └── utils.ts
├── index.html
├── manifest.json
└── sw.js
Then, I want to use my custom component in a way similar to:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Title of the document</title>
<script src="..."></script>
<script src="https://my.repository.com/components/comp-workspace.js"></script>
</head>
<body>
<comp-workspace attr1="..." attr2="..." attr3="..." ...></comp-workspace>
</body>
</html>
If I run the build
command on the console I get the following output:
$ npm run build
> @ionic/pwa-toolkit@0.0.1 build D:\stencil-lab
> stencil build
[25:03.5] @stencil/core v0.12.1
[25:03.9] build, app, prod mode, started ...
[25:06.3] transpile started ...
[25:12.3] transpile finished in 6.02 s
[25:15.5] module map started ...
[25:15.5] generate styles started ...
[25:26.0] compile global style start ...
[25:28.0] compile global style finish in 2.03 s
[25:28.0] generate styles finished in 12.50 s
[25:28.0] module map finished in 12.50 s
[25:28.0] generate bundles started ...
[25:28.2] generate bundles finished in 237 ms
[25:28.2] generate app files started ...
[25:29.6] generate app files finished in 1.36 s
[26:03.4] inject manifest into service worker started ...
[26:08.5] inject manifest into service worker finished in 5.04 s
[ WARN ] build warn
Generated an empty bundle
[26:08.5] build finished in 64.58 s
I also get a new directory: www
with the following content:
.
├── assets
│ └── icon
│ ├── favicon.ico
│ └── icon.png
├── build
│ ├── app
│ │ ├── 3hkybzk1.es5.js
│ │ ├── 3hkybzk1.js
│ │ ├── 3hkybzk1.sc.es5.js
│ │ ├── 3hkybzk1.sc.js
│ │ ├── 4jakisfl.es5.js
│ │ ├── 4jakisfl.js
│ │ ├── 4jakisfl.sc.es5.js
│ │ ├── 4jakisfl.sc.js
│ │ ├── aa33sq6q.es5.js
│ │ ├── aa33sq6q.js
│ │ ├── [... AND MANY MORE FILES]
│ │ └── svg
│ │ ├── index.js
│ │ ├── ios-add-circle-outline.svg
│ │ ├── ios-add-circle.svg
│ │ ├── ios-add.svg
│ │ ├── ios-airplane.svg
│ │ ├── ios-alarm.svg
│ │ ├── ios-albums.svg
│ │ ├── ios-alert.svg
│ │ ├── ios-american-football.svg
│ │ ├── ios-analytics.svg
│ │ └── [... AND MANY MORE FILES]
│ ├── app.css
│ └── app.js
├── index.html
├── manifest.json
├── sw.js
└── workbox-v3.4.1
├── workbox-background-sync.dev.js
├── workbox-background-sync.dev.js.map
├── workbox-background-sync.prod.js
├── workbox-background-sync.prod.js.map
├── workbox-broadcast-cache-update.dev.js
├── workbox-broadcast-cache-update.dev.js.map
├── workbox-broadcast-cache-update.prod.js
├── workbox-broadcast-cache-update.prod.js.map
├── workbox-cache-expiration.dev.js
├── workbox-cache-expiration.dev.js.map
└── [... AND MANY MORE FILES]
6 directories, 832 files
but as you can see, I don’t get an actual javascript bundle file I can use to insert my custom component on any vanilla HTML/Javascript
page.
My question is: how do I build
just my custom component from inside this Ionic 4 PWA
app?
Thanks!