Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom pwa elements #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@capacitor/cli": "^3.6.0",
"@capacitor/core": "^3.6.0",
"@ionic/cli": "^6.20.1",
"@ionic/pwa-elements": "^3.1.1",
"@ionic/vue": "^6.1.11",
"@ionic/vue-router": "^6.1.11",
"@kevinmarrec/nuxt-pwa": "^0.3.0",
Expand Down
5 changes: 5 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
modules: ['nuxt-ionic'],
ionic: {
integrations: {
pwa: {
enableElements: true,
},
},
// integrations: {
// meta: true,
// pwa: true,
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import { setupMeta } from './parts/meta'
import { setupPWA } from './parts/pwa'
import { setupRouter } from './parts/router'

interface PwaOptions {
enableElements?: boolean
}

export interface ModuleOptions {
integrations?: {
router?: boolean
pwa?: boolean
pwa?: boolean | PwaOptions
meta?: boolean
}
css?: {
Expand All @@ -33,7 +37,9 @@ export default defineNuxtModule<ModuleOptions>({
defaults: {
integrations: {
meta: true,
pwa: true,
pwa: {
enableElements: false,
},
router: true,
},
css: {
Expand Down Expand Up @@ -108,6 +114,11 @@ export default defineNuxtModule<ModuleOptions>({

if (options.integrations?.pwa) {
await setupPWA()

// If it isn't true, it must be a PWA options object
if (options.integrations.pwa != true && options.integrations.pwa?.enableElements) {
addPlugin(resolve(runtimeDir, 'customElements.client'))
}
}

// Set up Ionic Router integration
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/customElements.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineCustomElements } from '@ionic/pwa-elements/loader'
import { defineNuxtPlugin } from '#imports'

export default defineNuxtPlugin(nuxtApp => {
nuxtApp.hook('app:mounted', () => {
defineCustomElements(window)
})
})