vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.33k stars 348 forks source link

Make `+client.js` cumulative #1834

Open brillout opened 2 months ago

brillout commented 2 months ago

Description

Currently +client.js isn't cumulative. But it should be.

pages/+client.js
# This currently overrides pages/+client.js (but it shouldn't)
pages/some-page/+client.js

In the meantime the workaround is to do this:

// pages/some-page/+client.js

// Import pages/+client.js
import '../client.js'
aheissenberger commented 2 months ago

My first use case is adding Sentry Browser Error Tracking. For this the requirements is to be load on all pages.

My second use case was adding a simple script to one of the pages in a setup without any frontend framework (plain html). This script is only relevant on the page in the same folder and not relevant to pages in any folder beneath.

I think your workaround is not such a bad solution except for the ../../../+client.js in deeper folders which could be fixed with some configurations setting.

Maybe an update of the documentation would help:

  1. information about +client.js not being cumulative
  2. solution for use cases which need composition of global and local
brillout commented 2 months ago
  1. Done.
  2. Correct me if I'm wrong but I guess the workaround mentioned here does the trick for now.

(Btw. your contributions to Bati are very much appreciated :green_heart: feel free to PM me on Discord!)