fastify-vite icon indicating copy to clipboard operation
fastify-vite copied to clipboard

isServer doesn't work as import.meta.env.SSR

Open davidmeirlevy opened this issue 2 years ago • 1 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.23.1

Plugin version

2.3.0

Node.js version

14.7

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

11.6

Description

my app is using vue-ts

SSR code should be tree-shaked from client dist

Steps to Reproduce

write something like:

if(import.meta.env.SSR) {
  // code that will tree-shaked from client dist.
}

when doing:

import {isServer} from 'fastify-vite-vue/client.mjs';

if(isServer) {
  // code that will NOT tree-shaked from client dist.
}

Expected Behavior

SSR code should be tree-shaked from client dist

davidmeirlevy avatar Nov 26 '21 12:11 davidmeirlevy

Good catch — I think the workaround for now is to just use import.meta if you we're using /client.mjs — probably doesn't make sense to keep /client.js available in renderer adapters given all Vite application code is ESM. So not really a workaround but rather a fix. Feel free to put a PR up, I should be able to get to it (and a new release) tomorrow in any case.

galvez avatar Nov 26 '21 12:11 galvez