fastify / fastify-vite

Fastify plugin for Vite integration.
MIT License
850 stars 72 forks source link

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

Open davidmeirlevy opened 2 years ago

davidmeirlevy commented 2 years ago

Prerequisites

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

galvez commented 2 years ago

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.