Skip to content

Commit

Permalink
feat: add option and interface for @ionic/vue global config (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrdtr authored Aug 17, 2022
1 parent 82bff58 commit 7df1aae
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/content/2.getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export default defineNuxtConfig({
css: {
//
},
config: {
//
}
},
})
```
Expand Down Expand Up @@ -117,3 +120,7 @@ export default defineNuxtConfig({

Default: `false`
Enable to add extra Ionic CSS utilities.

### `config`

- See [Config Options](https://ionicframework.com/docs/vue/config#config-options)
53 changes: 51 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, promises as fsp } from 'node:fs'

import { defineNuxtModule, addComponent, addPlugin } from '@nuxt/kit'
import { defineNuxtModule, addComponent, addPlugin, addTemplate } from '@nuxt/kit'
import { join, resolve } from 'pathe'
import { readPackageJSON } from 'pkg-types'
import { defineUnimportPreset } from 'unimport'
Expand All @@ -13,6 +13,8 @@ import { setupMeta } from './parts/meta'
import { setupPWA } from './parts/pwa'
import { setupRouter } from './parts/router'

import type { AnimationBuilder, SpinnerTypes, PlatformConfig } from '@ionic/vue'

export interface ModuleOptions {
integrations?: {
router?: boolean
Expand All @@ -25,6 +27,46 @@ export interface ModuleOptions {
basic?: boolean
utilities?: boolean
}
config?: {
actionSheetEnter?: AnimationBuilder
actionSheetLeave?: AnimationBuilder
alertEnter?: AnimationBuilder
alertLeave?: AnimationBuilder
animated?: boolean
backButtonIcon?: string
backButtonText?: string
hardwareBackButton?: boolean
infiniteLoadingSpinner?: SpinnerTypes
loadingEnter?: AnimationBuilder
loadingLeave?: AnimationBuilder
loadingSpinner?: SpinnerTypes
menuIcon?: string
menuType?: string
modalEnter?: AnimationBuilder
modalLeave?: AnimationBuilder
mode?: 'ios' | 'md'
navAnimation?: AnimationBuilder
pickerEnter?: AnimationBuilder
pickerLeave?: AnimationBuilder
platform?: PlatformConfig
popoverEnter?: AnimationBuilder
popoverLeave?: AnimationBuilder
refreshingIcon?: string
refreshingSpinner?: SpinnerTypes
sanitizerEnabled?: boolean
spinner?: SpinnerTypes
statusTap?: boolean
swipeBackEnabled?: boolean
tabButtonLayout?:
| 'icon-top'
| 'icon-start'
| 'icon-end'
| 'icon-bottom'
| 'icon-hide'
| 'label-hide'
toastEnter?: AnimationBuilder
toastLeave?: AnimationBuilder
}
}

export default defineNuxtModule<ModuleOptions>({
Expand All @@ -44,12 +86,19 @@ export default defineNuxtModule<ModuleOptions>({
basic: true,
utilities: false,
},
config: {},
},
async setup(options, nuxt) {
nuxt.options.build.transpile.push(runtimeDir)
nuxt.options.build.transpile.push(/@ionic/, /@stencil/)

// Set up Ionic config
// Inject options for the Ionic Vue plugin as a virtual module
addTemplate({
filename: 'ionic/vue-config.mjs',
getContents: () => `export default ${JSON.stringify(options.config)}`,
})

// Set up Ionic config file
const ionicConfigPath = join(nuxt.options.rootDir, 'ionic.config.json')
if (!existsSync(ionicConfigPath)) {
await fsp.writeFile(
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/ionic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IonicVue } from '@ionic/vue'
import { defineNuxtPlugin } from '#imports'
// @ts-expect-error virtual template
import ionicVueConfig from '#build/ionic/vue-config.mjs'

export default defineNuxtPlugin(nuxtApp => {
nuxtApp.vueApp.use(IonicVue)
nuxtApp.vueApp.use(IonicVue, ionicVueConfig)
})

1 comment on commit 7df1aae

@vercel
Copy link

@vercel vercel bot commented on 7df1aae Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.