2021-10-07 08:31:29 +00:00
|
|
|
import { addVitePlugin, addWebpackPlugin, useNuxt } from '@nuxt/kit'
|
2021-10-11 08:21:45 +00:00
|
|
|
import scriptSetupPlugin from 'unplugin-vue2-script-setup'
|
2021-11-29 12:17:29 +00:00
|
|
|
import type { ScriptSetupOptions } from '../types'
|
2021-10-07 08:31:29 +00:00
|
|
|
|
2021-11-29 12:17:29 +00:00
|
|
|
export const setupScriptSetup = (options: ScriptSetupOptions) => {
|
2021-10-07 08:31:29 +00:00
|
|
|
const nuxt = useNuxt()
|
2021-11-29 12:17:29 +00:00
|
|
|
const config = options === true ? {} : options
|
2021-10-07 08:31:29 +00:00
|
|
|
|
2021-11-29 12:17:29 +00:00
|
|
|
addVitePlugin(scriptSetupPlugin.vite(config))
|
|
|
|
addWebpackPlugin(scriptSetupPlugin.webpack(config))
|
2021-10-07 08:31:29 +00:00
|
|
|
|
|
|
|
nuxt.hook('prepare:types', ({ references }) => {
|
|
|
|
references.push({
|
|
|
|
types: 'unplugin-vue2-script-setup/types'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|