feat(bridge): allow user-defined scriptSetup options (#2185)

Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
Yasser Lahbibi 2021-11-29 13:17:29 +01:00 committed by GitHub
parent 2c4a001b77
commit ac98373b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -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()

View File

@ -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({

View File

@ -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