-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathglobalConfig.ts
More file actions
25 lines (22 loc) · 944 Bytes
/
globalConfig.ts
File metadata and controls
25 lines (22 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { libraryName } from '../config'
import type { ModuleOptions } from '../types'
import { camelize, resolveComponentPath } from '../utils'
export function resolveGlobalConfig (config: ModuleOptions) {
const { globalConfig, cache, defaultLocale } = config
const needLocale = !!(cache && defaultLocale)
const locale = camelize(defaultLocale ?? '')
let provideConfig = JSON.stringify(globalConfig)
if (needLocale) {
provideConfig = JSON.stringify(Object.assign({}, globalConfig, { locale })).replace(`"${locale}"`, locale)
}
return {
filename: `${libraryName}-globalConfig.plugin.mjs`,
getContents: async () => {
return `import { defineNuxtPlugin, provideGlobalConfig } from '#imports';
${needLocale ? `import { ${locale} } from '${await resolveComponentPath('', cache)}';\n` : ''}
export default defineNuxtPlugin(nuxtApp => {
provideGlobalConfig(${provideConfig}, nuxtApp.vueApp, true);
})`
}
}
}