Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [
[
"@effex/core",
"@effex/dom",
"@effex/router",
"@effex/form",
"@effex/platform",
"@effex/vite-plugin",
"create-effex"
]
],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true
}
}
82 changes: 82 additions & 0 deletions apps/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# docs

## 0.0.10

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@1.1.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.9

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.8

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.7

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.6

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.5

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.4

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.3

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@1.1.0
- @effex/dom@1.1.0

## 0.0.2

### Patch Changes

- Updated dependencies [5023cff]
- @effex/platform@2.0.0
- @effex/router@2.0.0
- @effex/dom@2.0.0
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.1",
"version": "0.0.10",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./styles.css";

import { Effect } from "effect";

import { hydrate } from "@effex/dom/hydrate";
Expand Down
6 changes: 3 additions & 3 deletions packages/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"build": "tsup"
},
"dependencies": {
"@effex/core": "workspace:*"
"@effex/core": "workspace:^"
},
"peerDependencies": {
"@effect/platform": "^0.94.0",
"@effex/dom": "workspace:*",
"@effex/router": "workspace:*",
"@effex/dom": "workspace:^",
"@effex/router": "workspace:^",
"effect": "^3.0.0"
},
"peerDependenciesMeta": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build": "tsup"
},
"peerDependencies": {
"@effex/platform": "workspace:*",
"@effex/platform": "workspace:^",
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
},
"peerDependenciesMeta": {
Expand Down
54 changes: 51 additions & 3 deletions packages/vite-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from "node:fs";
import * as path from "node:path";

import type { Plugin, ViteDevServer } from "vite";
Expand Down Expand Up @@ -82,6 +83,17 @@ export const effexPlatform = (options: EffexPlatformOptions = {}): Plugin => {
return {
name: "effex-platform",

config(config) {
// Prevent the SSR build from wiping the client build's output
if (config.build?.ssr) {
return {
build: {
emptyOutDir: false,
},
};
}
},

configResolved(config) {
root = config.root;
outDir = path.resolve(root, config.build?.outDir ?? "dist");
Expand Down Expand Up @@ -248,8 +260,6 @@ export const effexPlatform = (options: EffexPlatformOptions = {}): Plugin => {
try {
// Dynamically import the built SSG entry.
// The entry must export: { router, app?, document?, layers? }
// The SSR build should have already been run (vite build --ssr)
// and the entry compiled. We import the built version.
// Dynamic import — @effex/platform is an optional peer dependency
// only needed for SSG mode at build time
const platformModule = "@effex/platform";
Expand All @@ -268,10 +278,48 @@ export const effexPlatform = (options: EffexPlatformOptions = {}): Plugin => {
);
}

// Read the client-built index.html to extract actual asset paths.
// Vite processes scripts/styles and outputs hashed filenames —
// we need those real paths instead of the source paths in document options.
const clientHtmlPath = path.resolve(outDir, "index.html");
const documentOptions = { ...entryModule.document };

if (fs.existsSync(clientHtmlPath)) {
const clientHtml = fs.readFileSync(clientHtmlPath, "utf-8");

// Extract script src attributes from the Vite-processed HTML
const scriptMatches = [
...clientHtml.matchAll(/<script[^>]+src="([^"]+)"[^>]*>/g),
];
// Replace source paths with the real hashed asset paths.
// If no scripts found in client HTML, keep the original (shouldn't happen).
if (scriptMatches.length > 0) {
documentOptions.scripts = scriptMatches.map(
(m: RegExpMatchArray) => m[1],
);
}

// Extract stylesheet href attributes.
// Check both attribute orderings (rel before href, href before rel).
const styleMatches = [
...clientHtml.matchAll(
/<link[^>]+rel="stylesheet"[^>]+href="([^"]+)"[^>]*>/g,
),
...clientHtml.matchAll(
/<link[^>]+href="([^"]+)"[^>]+rel="stylesheet"[^>]*>/g,
),
];
// Always override — if Vite bundled CSS into JS (e.g. Tailwind),
// there are no stylesheet links and we should clear the source paths.
documentOptions.styles = styleMatches.map(
(m: RegExpMatchArray) => m[1],
);
}

await buildStaticSite({
router: entryModule.router,
app: entryModule.app,
document: entryModule.document,
document: documentOptions,
outDir,
layers: entryModule.layers,
});
Expand Down
Loading
Loading