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-26 12:59:05 +00:00
|
|
|
// Resolve vue2 builds
|
|
|
|
nuxt.options.alias.vue2 = resolveModule('vue/dist/vue.runtime.esm.js', { paths: nuxt.options.modulesDir })
|
|
|
|
nuxt.options.build.transpile.push('vue')
|
|
|
|
|
2021-11-11 16:46:10 +00:00
|
|
|
// Disable legacy fetch polyfills
|
|
|
|
nuxt.options.fetch.server = false
|
|
|
|
nuxt.options.fetch.client = false
|
|
|
|
|
2021-10-26 12:59:05 +00:00
|
|
|
// Alias vue to have identical vue3 exports
|
|
|
|
nuxt.options.alias['vue2-bridge'] = resolve(distDir, 'runtime/vue2-bridge.mjs')
|
2021-10-12 20:16:43 +00:00
|
|
|
for (const alias of [
|
2021-10-26 12:59:05 +00:00
|
|
|
// vue
|
|
|
|
'vue',
|
2021-10-12 20:16:43 +00:00
|
|
|
// vue 3 helper packages
|
|
|
|
'@vue/shared',
|
|
|
|
'@vue/reactivity',
|
2021-10-26 12:59:05 +00:00
|
|
|
'@vue/runtime-core',
|
|
|
|
'@vue/runtime-dom',
|
2021-10-12 20:16:43 +00:00
|
|
|
...[
|
|
|
|
// vue 2 dist files
|
|
|
|
'vue/dist/vue.common.dev',
|
|
|
|
'vue/dist/vue.common',
|
|
|
|
'vue/dist/vue.common.prod',
|
|
|
|
'vue/dist/vue.esm.browser',
|
|
|
|
'vue/dist/vue.esm.browser.min',
|
|
|
|
'vue/dist/vue.esm',
|
|
|
|
'vue/dist/vue',
|
|
|
|
'vue/dist/vue.min',
|
|
|
|
'vue/dist/vue.runtime.common.dev',
|
|
|
|
'vue/dist/vue.runtime.common',
|
|
|
|
'vue/dist/vue.runtime.common.prod',
|
|
|
|
'vue/dist/vue.runtime.esm',
|
|
|
|
'vue/dist/vue.runtime',
|
|
|
|
'vue/dist/vue.runtime.min'
|
|
|
|
].flatMap(m => [m, `${m}.js`])
|
|
|
|
]) {
|
2021-10-26 12:59:05 +00:00
|
|
|
nuxt.options.alias[alias] = nuxt.options.alias['vue2-bridge']
|
2021-10-12 20:16:43 +00:00
|
|
|
}
|
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)) {
|
2021-10-22 17:04:15 +00:00
|
|
|
// @ts-ignore
|
|
|
|
const jsRule: any = config.module.rules.find(rule => rule.test instanceof RegExp && rule.test.test('index.mjs'))
|
|
|
|
jsRule.type = 'javascript/auto'
|
|
|
|
|
|
|
|
config.module.rules.unshift({
|
|
|
|
test: /\.mjs$/,
|
|
|
|
type: 'javascript/auto',
|
|
|
|
include: [/node_modules/]
|
|
|
|
})
|
2021-09-05 21:21:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|