Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module): pass options to init method of aos
- Loading branch information
Showing
4 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit' | ||
import { defineNuxtModule, addPlugin, createResolver } from "@nuxt/kit"; | ||
import { name, version } from "../package.json"; | ||
import { AosOptions } from "aos"; | ||
|
||
export interface ModuleOptions {} | ||
export interface ModuleOptions { | ||
options?: AosOptions; | ||
} | ||
|
||
export default defineNuxtModule<ModuleOptions>({ | ||
meta: { | ||
name: 'nuxt-aos', | ||
name, | ||
version, | ||
configKey: "aos", | ||
}, | ||
defaults: {}, | ||
setup () { | ||
const resolver = createResolver(import.meta.url) | ||
defaults: { | ||
options: {}, | ||
}, | ||
setup(options, nuxt) { | ||
const resolver = createResolver(import.meta.url); | ||
|
||
// Get runtimeConfig & add aos to it so we can access it in plugin | ||
const config = useRuntimeConfig(); | ||
config.public.aos = options.options; | ||
|
||
addPlugin(resolver.resolve('./runtime/plugin')) | ||
} | ||
}) | ||
addPlugin(resolver.resolve("./runtime/plugin")); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { defineNuxtPlugin } from '#app' | ||
import { defineNuxtPlugin } from "#app"; | ||
|
||
import AOS from "aos" | ||
import "aos/dist/aos.css" | ||
import AOS from "aos"; | ||
import "aos/dist/aos.css"; | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
const config = useRuntimeConfig(); | ||
if (typeof window !== "undefined") { | ||
nuxtApp.AOS = AOS.init() | ||
nuxtApp.AOS = AOS.init(config.public?.aos || {}); | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters