2021-09-05 21:21:33 +00:00
|
|
|
import { useNuxt, resolveModule } from '@nuxt/kit'
|
2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-09-05 21:21:33 +00:00
|
|
|
import { distDir } from './dirs'
|
|
|
|
|
2021-09-22 15:34:11 +00:00
|
|
|
export function setupAppBridge (_options: any) {
|
2021-09-05 21:21:33 +00:00
|
|
|
const nuxt = useNuxt()
|
|
|
|
|
|
|
|
// Setup aliases
|
|
|
|
nuxt.options.alias['#app'] = resolve(distDir, 'runtime/index.mjs')
|
|
|
|
nuxt.options.alias['#build'] = nuxt.options.buildDir
|
|
|
|
|
2021-10-06 12:37:45 +00:00
|
|
|
// Alias vue to a vue3-compat version of vue2
|
|
|
|
nuxt.options.alias['#vue'] = nuxt.options.alias.vue || resolveModule('vue/dist/vue.runtime.esm.js', { paths: nuxt.options.modulesDir })
|
|
|
|
nuxt.options.alias['@vue/shared'] = 'vue'
|
|
|
|
nuxt.options.alias['@vue/reactivity'] = 'vue'
|
|
|
|
nuxt.options.alias.vue = resolve(distDir, 'runtime/vue.mjs')
|
|
|
|
nuxt.options.build.transpile.push('vue')
|
2021-09-05 21:21:33 +00:00
|
|
|
|
2021-09-29 10:38:44 +00:00
|
|
|
// Deprecate various Nuxt options
|
|
|
|
if (nuxt.options.globalName !== 'nuxt') {
|
|
|
|
throw new Error('Custom global name is not supported by @nuxt/bridge.')
|
|
|
|
}
|
|
|
|
|
2021-09-05 21:21:33 +00:00
|
|
|
// Fix wp4 esm
|
|
|
|
nuxt.hook('webpack:config', (configs) => {
|
|
|
|
for (const config of configs.filter(c => c.module)) {
|
|
|
|
for (const rule of config.module.rules) {
|
|
|
|
// @ts-ignore
|
|
|
|
if (rule.test instanceof RegExp && rule.test.test('index.mjs')) {
|
|
|
|
// @ts-ignore
|
|
|
|
rule.type = 'javascript/auto'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|