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

Commit 7c997c5

Browse files
authored
fix: alias module so we can access process.server in vite node build (#462)
1 parent d059dfd commit 7c997c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/module.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Module, NuxtOptions } from '@nuxt/types'
2-
import { relative, sep } from 'upath'
2+
import { relative, resolve, sep } from 'upath'
33

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

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

1919
addGlobalsFile.call(this)
2020

21+
// Add library alias for benefit of vite
22+
23+
nuxtOptions.alias['~composition-api'] = resolve(__dirname, 'index.mjs')
24+
2125
// Force transpilation of this library (to enable resolution of globals file)
2226

2327
nuxtOptions.build.transpile = nuxtOptions.build.transpile || []
24-
nuxtOptions.build.transpile.push('@nuxtjs/composition-api', __dirname)
28+
nuxtOptions.build.transpile.push(
29+
'@nuxtjs/composition-api',
30+
'~composition-api',
31+
__dirname
32+
)
2533

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

src/vite-plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export function compositionApiPlugin(): Plugin & { enforce: 'pre' } {
1717
name: 'nuxt:composition-api',
1818
enforce: 'pre',
1919
transform(code: string, filename: string) {
20+
code = code.replace(
21+
/@nuxtjs[\\/]composition-api(?![\\/])/g,
22+
'~composition-api'
23+
)
2024
const keyedFunctions = /(useStatic|shallowSsrRef|ssrPromise|ssrRef|reqSsrRef|useAsync)/
2125
if (!keyedFunctions.test(code)) {
2226
return {

0 commit comments

Comments
 (0)