Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: alias module so we can access process.server in vite node build #462

Merged
merged 4 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Module, NuxtOptions } from '@nuxt/types'
import { relative, sep } from 'upath'
import { relative, resolve, sep } from 'upath'

import { name, version } from '../package.json'

Expand All @@ -18,10 +18,18 @@ const compositionApiModule: Module<never> = function compositionApiModule() {

addGlobalsFile.call(this)

// Add library alias for benefit of vite

nuxtOptions.alias['~composition-api'] = resolve(__dirname, 'index.mjs')

// Force transpilation of this library (to enable resolution of globals file)

nuxtOptions.build.transpile = nuxtOptions.build.transpile || []
nuxtOptions.build.transpile.push('@nuxtjs/composition-api', __dirname)
nuxtOptions.build.transpile.push(
'@nuxtjs/composition-api',
'~composition-api',
__dirname
)

// Define @vue/composition-api resolution to prevent using different versions of @vue/composition-api

Expand Down
4 changes: 4 additions & 0 deletions src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function compositionApiPlugin(): Plugin & { enforce: 'pre' } {
name: 'nuxt:composition-api',
enforce: 'pre',
transform(code: string, filename: string) {
code = code.replace(
/@nuxtjs[\\/]composition-api(?![\\/])/g,
'~composition-api'
)
const keyedFunctions = /(useStatic|shallowSsrRef|ssrPromise|ssrRef|reqSsrRef|useAsync)/
if (!keyedFunctions.test(code)) {
return {
Expand Down