Nuxt/packages/bridge/src/module.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-09-05 21:21:33 +00:00
import { defineNuxtModule, installModule } from '@nuxt/kit'
import { setupNitroBridge } from './nitro'
import { setupAppBridge } from './app'
import { setupCAPIBridge } from './capi'
import { setupBetterResolve } from './resolve'
2021-09-05 21:21:33 +00:00
export default defineNuxtModule({
name: 'nuxt-bridge',
configKey: 'bridge',
defaults: {
nitro: true,
vite: false,
app: {},
capi: {},
2021-09-05 21:21:33 +00:00
// TODO: Remove from 2.16
postcss8: true,
swc: true,
resolve: true
2021-09-05 21:21:33 +00:00
},
async setup (opts, nuxt) {
if (opts.nitro) {
await setupNitroBridge()
}
if (opts.app) {
await setupAppBridge(opts.app)
}
if (opts.capi) {
if (!opts.app) {
throw new Error('[bridge] Cannot enable composition-api with app disabled!')
}
await setupCAPIBridge(opts.capi)
2021-09-05 21:21:33 +00:00
}
if (opts.vite) {
await installModule(nuxt, require.resolve('nuxt-vite'))
}
if (opts.postcss8) {
await installModule(nuxt, require.resolve('@nuxt/postcss8'))
}
if (opts.swc) {
await installModule(nuxt, require.resolve('nuxt-swc'))
}
if (opts.resolve) {
setupBetterResolve()
}
2021-09-05 21:21:33 +00:00
}
})