mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
2db79adfb8
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
27 lines
610 B
TypeScript
27 lines
610 B
TypeScript
|
|
import { NuxtApp } from './app'
|
|
import { Builder } from './builder'
|
|
import { resolveFiles } from './utils'
|
|
|
|
export interface NuxtPlugin {
|
|
src: string
|
|
mode: 'server' | 'client' | 'all'
|
|
}
|
|
|
|
const MODES_REGEX = /\.(server|client)(\.\w+)*$/
|
|
const getPluginMode = (src: string) => {
|
|
const [, mode = 'all'] = src.match(MODES_REGEX) || []
|
|
|
|
return mode as NuxtPlugin['mode']
|
|
}
|
|
|
|
export async function resolvePlugins (builder: Builder, app: NuxtApp) {
|
|
const plugins = await resolveFiles(builder, 'plugins/**/*.{js,ts}', app.dir)
|
|
|
|
return plugins.map(src => ({
|
|
src,
|
|
mode: getPluginMode(src)
|
|
})
|
|
)
|
|
}
|