mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 09:25:54 +00:00
feat(bridge): allow user-defined scriptSetup
options (#2185)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
2c4a001b77
commit
ac98373b4c
@ -1,6 +1,6 @@
|
|||||||
import { createRequire } from 'module'
|
import { createRequire } from 'module'
|
||||||
import { defineNuxtModule, installModule, checkNuxtCompatibilityIssues } from '@nuxt/kit'
|
import { defineNuxtModule, installModule, checkNuxtCompatibilityIssues } from '@nuxt/kit'
|
||||||
import type { BridgeConfig } from '../types'
|
import type { BridgeConfig, ScriptSetupOptions } from '../types'
|
||||||
import { setupNitroBridge } from './nitro'
|
import { setupNitroBridge } from './nitro'
|
||||||
import { setupAppBridge } from './app'
|
import { setupAppBridge } from './app'
|
||||||
import { setupCAPIBridge } from './capi'
|
import { setupCAPIBridge } from './capi'
|
||||||
@ -45,7 +45,7 @@ export default defineNuxtModule({
|
|||||||
await setupCAPIBridge(opts.capi)
|
await setupCAPIBridge(opts.capi)
|
||||||
}
|
}
|
||||||
if (opts.scriptSetup) {
|
if (opts.scriptSetup) {
|
||||||
await setupScriptSetup()
|
await setupScriptSetup(opts.scriptSetup as ScriptSetupOptions)
|
||||||
}
|
}
|
||||||
if (opts.autoImports) {
|
if (opts.autoImports) {
|
||||||
await setupAutoImports()
|
await setupAutoImports()
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { addVitePlugin, addWebpackPlugin, useNuxt } from '@nuxt/kit'
|
import { addVitePlugin, addWebpackPlugin, useNuxt } from '@nuxt/kit'
|
||||||
import scriptSetupPlugin from 'unplugin-vue2-script-setup'
|
import scriptSetupPlugin from 'unplugin-vue2-script-setup'
|
||||||
|
import type { ScriptSetupOptions } from '../types'
|
||||||
|
|
||||||
export const setupScriptSetup = () => {
|
export const setupScriptSetup = (options: ScriptSetupOptions) => {
|
||||||
const nuxt = useNuxt()
|
const nuxt = useNuxt()
|
||||||
|
const config = options === true ? {} : options
|
||||||
|
|
||||||
addVitePlugin(scriptSetupPlugin.vite())
|
addVitePlugin(scriptSetupPlugin.vite(config))
|
||||||
addWebpackPlugin(scriptSetupPlugin.webpack())
|
addWebpackPlugin(scriptSetupPlugin.webpack(config))
|
||||||
|
|
||||||
nuxt.hook('prepare:types', ({ references }) => {
|
nuxt.hook('prepare:types', ({ references }) => {
|
||||||
references.push({
|
references.push({
|
||||||
|
5
packages/bridge/types.d.ts
vendored
5
packages/bridge/types.d.ts
vendored
@ -1,13 +1,16 @@
|
|||||||
import type {} from '@nuxt/nitro'
|
import type {} from '@nuxt/nitro'
|
||||||
import type { NuxtConfig as _NuxtConfig } from '@nuxt/schema'
|
import type { NuxtConfig as _NuxtConfig } from '@nuxt/schema'
|
||||||
import type { MetaInfo } from 'vue-meta'
|
import type { MetaInfo } from 'vue-meta'
|
||||||
|
import type { PluginOptions as ScriptSetupPluginOptions } from 'unplugin-vue2-script-setup/dist'
|
||||||
|
|
||||||
|
export type ScriptSetupOptions = ScriptSetupPluginOptions
|
||||||
|
|
||||||
export interface BridgeConfig {
|
export interface BridgeConfig {
|
||||||
nitro: boolean
|
nitro: boolean
|
||||||
vite: boolean
|
vite: boolean
|
||||||
app: boolean | {}
|
app: boolean | {}
|
||||||
capi: boolean | {}
|
capi: boolean | {}
|
||||||
scriptSetup: boolean
|
scriptSetup: boolean | ScriptSetupOptions
|
||||||
autoImports: boolean
|
autoImports: boolean
|
||||||
transpile: boolean
|
transpile: boolean
|
||||||
constraints: boolean
|
constraints: boolean
|
||||||
|
Loading…
Reference in New Issue
Block a user