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

Commit

Permalink
fix: alias module so we can access process.server in vite node build (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Apr 24, 2021
1 parent d059dfd commit 7c997c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit 7c997c5

Please sign in to comment.