2021-10-02 16:01:17 +00:00
|
|
|
import { createRequire } from 'module'
|
2021-09-05 21:21:33 +00:00
|
|
|
import { defineNuxtModule, installModule } from '@nuxt/kit'
|
|
|
|
import { setupNitroBridge } from './nitro'
|
|
|
|
import { setupAppBridge } from './app'
|
2021-09-22 15:34:11 +00:00
|
|
|
import { setupCAPIBridge } from './capi'
|
2021-10-02 11:44:30 +00:00
|
|
|
import { setupBetterResolve } from './resolve'
|
2021-10-02 16:59:32 +00:00
|
|
|
import { setupGlobalImports } from './global-imports'
|
2021-09-05 21:21:33 +00:00
|
|
|
|
|
|
|
export default defineNuxtModule({
|
|
|
|
name: 'nuxt-bridge',
|
|
|
|
configKey: 'bridge',
|
|
|
|
defaults: {
|
|
|
|
nitro: true,
|
|
|
|
vite: false,
|
2021-09-22 15:34:11 +00:00
|
|
|
app: {},
|
|
|
|
capi: {},
|
2021-10-02 16:59:32 +00:00
|
|
|
globalImports: true,
|
2021-09-05 21:21:33 +00:00
|
|
|
// TODO: Remove from 2.16
|
|
|
|
postcss8: true,
|
2021-10-02 11:44:30 +00:00
|
|
|
swc: true,
|
|
|
|
resolve: true
|
2021-09-05 21:21:33 +00:00
|
|
|
},
|
|
|
|
async setup (opts, nuxt) {
|
2021-10-02 16:59:32 +00:00
|
|
|
const _require = createRequire(import.meta.url)
|
|
|
|
|
2021-09-05 21:21:33 +00:00
|
|
|
if (opts.nitro) {
|
|
|
|
await setupNitroBridge()
|
|
|
|
}
|
|
|
|
if (opts.app) {
|
2021-09-22 15:34:11 +00:00
|
|
|
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
|
|
|
}
|
2021-10-02 16:59:32 +00:00
|
|
|
if (opts.globalImports) {
|
|
|
|
await setupGlobalImports()
|
|
|
|
}
|
2021-09-05 21:21:33 +00:00
|
|
|
if (opts.vite) {
|
2021-10-02 16:01:17 +00:00
|
|
|
await installModule(nuxt, _require.resolve('nuxt-vite'))
|
2021-09-05 21:21:33 +00:00
|
|
|
}
|
|
|
|
if (opts.postcss8) {
|
2021-10-02 16:01:17 +00:00
|
|
|
await installModule(nuxt, _require.resolve('@nuxt/postcss8'))
|
2021-09-05 21:21:33 +00:00
|
|
|
}
|
|
|
|
if (opts.swc) {
|
2021-10-02 16:01:17 +00:00
|
|
|
await installModule(nuxt, _require.resolve('nuxt-swc'))
|
2021-09-05 21:21:33 +00:00
|
|
|
}
|
2021-10-02 11:44:30 +00:00
|
|
|
if (opts.resolve) {
|
|
|
|
setupBetterResolve()
|
|
|
|
}
|
2021-09-05 21:21:33 +00:00
|
|
|
}
|
|
|
|
})
|