fix(nuxt): fully resolve unctx where possible (#22811)

This commit is contained in:
Daniel Roe 2023-08-25 14:57:25 +01:00 committed by GitHub
parent a352d59a58
commit 9bee320c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -16,6 +16,7 @@ import importsModule from '../imports/module'
import { distDir, pkgDir } from '../dirs'
import { version } from '../../package.json'
import { ImportProtectionPlugin, vueAppPatterns } from './plugins/import-protection'
import type { UnctxTransformPluginOptions } from './plugins/unctx'
import { UnctxTransformPlugin } from './plugins/unctx'
import type { TreeShakeComposablesPluginOptions } from './plugins/tree-shake'
import { TreeShakeComposablesPlugin } from './plugins/tree-shake'
@ -110,12 +111,15 @@ async function initNuxt (nuxt: Nuxt) {
}))
}
nuxt.hook('modules:done', () => {
nuxt.hook('modules:done', async () => {
// Add unctx transform
const options = {
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client,
transformerOptions: nuxt.options.optimization.asyncTransforms
transformerOptions: {
...nuxt.options.optimization.asyncTransforms,
helperModule: await tryResolveModule('unctx', nuxt.options.modulesDir) ?? 'unctx'
}
} satisfies UnctxTransformPluginOptions
addVitePlugin(() => UnctxTransformPlugin.vite(options))
addWebpackPlugin(() => UnctxTransformPlugin.webpack(options))

View File

@ -6,7 +6,7 @@ import { isJS, isVue } from '../utils'
const TRANSFORM_MARKER = '/* _processed_nuxt_unctx_transform */\n'
interface UnctxTransformPluginOptions {
export interface UnctxTransformPluginOptions {
sourcemap?: boolean
transformerOptions: TransformerOptions
}