Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Mar 27, 2024
1 parent aee0a30 commit 3992ddb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default defineNuxtModule<ModuleOptions>({
async setup(config, nuxt) {
const { resolve } = createResolver(import.meta.url)
const { version } = await readPackageJSON(resolve('../package.json'))
if (config.enabled === false) {
if (!config.enabled) {
// TODO fallback to useHead
logger.debug('The module is disabled, skipping setup.')
return
Expand All @@ -82,9 +82,11 @@ export default defineNuxtModule<ModuleOptions>({
return `import { defineNuxtPlugin, useScript } from '#imports'
export default defineNuxtPlugin({
setup() {
${config.globals?.map(g => typeof g === 'string'
? ` useScript("${g}")`
: ` useScript(${JSON.stringify(g[0])}, ${JSON.stringify(g[1])} })`).join('\n')}
${config.globals?.map(g => !Array.isArray(g)
? ` useScript("${g.toString()}")`
: g.length === 2
? ` useScript(${JSON.stringify(g[0])}, ${JSON.stringify(g[1])} })`
: ` useScript(${JSON.stringify(g[0])})`).join('\n')
}
})`
},
Expand Down

0 comments on commit 3992ddb

Please sign in to comment.