Skip to content

fix: tolerate static file imports in config files (brillout/docpress#86)#3123

Merged
brillout merged 34 commits intomainfrom
brillout/dev
Feb 26, 2026
Merged

fix: tolerate static file imports in config files (brillout/docpress#86)#3123
brillout merged 34 commits intomainfrom
brillout/dev

Conversation

@brillout brillout force-pushed the brillout/dev branch 2 times, most recently from d59db8e to 7c3697d Compare February 26, 2026 19:32
brillout and others added 28 commits February 26, 2026 22:24
…lation

Non-JS imports (e.g. .svg, .css) are now resolved to
'STATIC_FILE_NOT_AVAILABLE:/path/to/file' instead of being
treated as pointer imports, enabling files with
`env: { config: true, client: true }` to be loaded in Node.js.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 82a19ffcde861d0e97f6b3a0d2d4bb007b82b643.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… not stubs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use a cached esbuild sub-call to enumerate a file's exports,
so that named imports from runtime-tagged or non-script files
all resolve to the STATIC_FILE_NOT_AVAILABLE stub string.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Instead of a sub-build to enumerate exports, reuse the existing
Babel-based pointer import transform: mark with{type:'runtime'}
imports as 'static' in the pointerImports map so that
transformPointerImports replaces each specifier with
STATIC_FILE_NOT_AVAILABLE:<path>.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Convert STATIC_FILE_NOT_AVAILABLE:path strings to import statements
during config value serialization, just like pointer import strings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Multiple config values with the same STATIC_FILE_NOT_AVAILABLE (or
pointer import) path were generating redundant import bindings.
Use a WeakMap keyed on the importStatements array to reuse existing
import names for same path+export pairs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit b3964dea5a2b4336dade2468257c145653e34027.
Store Vite-compatible paths in STATIC_FILE_NOT_AVAILABLE strings:
- vike-static-file onLoad: convert abs path to root-relative (/@fs/ fallback)
- isStaticStub onResolve: store Vite path (npm name or root-relative) in
  pointerImports dict; update pointerImports.ts to use it as the path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…m paths"

This reverts commit 0384f63c48c372b1e269b6a14326afeef2cc4f14.
- with{type:'runtime'} script files: treat as regular pointer imports
  (import:path:exportName format) instead of static stubs, so export
  names are correctly encoded and the pointer import mechanism handles
  serialization.
- Remove 'static' type from pointerImports map; remove isStaticStub
  logic from pointerImports.ts.
- vike-static-file onLoad: convert abs filesystem path to Vite-compatible
  root-relative path (/@fs/ fallback) so the STATIC_FILE_NOT_AVAILABLE
  string contains the correct import path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add pluginStripRuntimeImportAttribute Vite plugin that removes
`with { type: 'runtime' }` attributes from import statements when
files are transpiled for client/server runtime. These attributes are
config-time only; leaving them in runtime code breaks bundlers and
runtimes that don't support unknown import attributes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lues

Config values loaded at config-time that contain STATIC_FILE_NOT_AVAILABLE
strings should not be converted to runtime imports. The serializer should
not be involved; the vike-static-file stub is only for preventing Node.js
crashes when config files import non-script files at config-time.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Non-plain-script value files (+docpress.tsx, +Component.vue, etc.) are
runtime-only files. Even when env.config=true, they should remain as
plus-file pointer imports rather than being evaluated at config-time.

This is consistent with the existing pointer-import logic in
transpileAndExecuteFile.ts:
  // .jsx, .vue, .svg, ... => obviously not config code => pointer import

Previously, the vike-static-file stub allowed these files to load
successfully at config-time (bypassing SVG/CSS import failures), causing
them to be serialized as 'js-serialized' instead of 'plus-file'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a +{configName}.js value file also runs in client or server
environments (env.client or env.server), its value must remain a
pointer import rather than being inlined as 'js-serialized' JSON.

This prevents value files like +docpress.tsx (env: { config, client,
server }) from being evaluated and inlined at config-time. Their imports
(SVG files, icon packages, etc.) should only be resolved by Vite at
runtime, not at config-time by esbuild.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…pe:runtime}"

This reverts commit 57d3e2059c2cd4ed905804b0fd51df4e573ca470.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@brillout brillout merged commit b170368 into main Feb 26, 2026
21 of 22 checks passed
@brillout brillout deleted the brillout/dev branch February 26, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant