Skip to content

Commit

Permalink
docs(changeset): move back to vite 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Oct 31, 2023
1 parent 9772c45 commit 978b04a
Show file tree
Hide file tree
Showing 13 changed files with 1,740 additions and 1,498 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-melons-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vinxi": patch
---

move back to vite 4
8 changes: 7 additions & 1 deletion examples/react/rsc/spa/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { serverFunctions } from "@vinxi/plugin-server-functions";
import reactRefresh from "@vitejs/plugin-react";
import { createApp } from "vinxi";

export default createApp({
const app = createApp({
routers: [
{
name: "public",
Expand Down Expand Up @@ -51,3 +51,9 @@ export default createApp({
},
],
});

app.hooks.hook("app:build:router:vite:config:resolved", ({ vite }) => {
console.log(vite.build.rollupOptions.input);
});

export default app;
2 changes: 1 addition & 1 deletion examples/solid/spa/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"solid-js": "^1.7.11",
"tailwindcss": "^3.3.3",
"vinxi": "0.0.42",
"vite": "^4.4.9",
"vite": "^4.5.0",
"vite-plugin-solid": "^2.7.0"
}
}
2 changes: 1 addition & 1 deletion examples/vanilla/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@vinxi/plugin-server-functions": "workspace:^",
"autoprefixer": "^10.4.15",
"tailwindcss": "^3.3.3",
"vinxi": "0.0.38"
"vinxi": "0.0.42"
}
}
2 changes: 1 addition & 1 deletion packages/vinxi-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/resolve": "^1.20.2",
"@types/unist": "^2.0.7",
"typescript": "^5.2.2",
"vite": "^4.4.9"
"vite": "^4.5.0"
},
"description": "Vite plugin for MDX",
"license": "MIT",
Expand Down
46 changes: 31 additions & 15 deletions packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { createIncomingMessage, createServerResponse } from "./http-stream.js";
import invariant from "./invariant.js";
import { consola, withLogger } from "./logger.js";
import { createSPAManifest } from "./manifest/spa-manifest.js";
import { handlerModule, join, relative, virtualId } from "./path.js";
import {
handlerModule,
join,
relative,
virtualId,
viteManifestPath,
} from "./path.js";
import { config } from "./plugins/config.js";
import { manifest } from "./plugins/manifest.js";
import { routes } from "./plugins/routes.js";
Expand Down Expand Up @@ -95,10 +101,7 @@ export async function createBuild(app, buildConfig) {
if (router.mode === "handler") {
invariant(router.handler, "Missing router.handler");
const bundlerManifest = JSON.parse(
readFileSync(
join(router.outDir, router.base, ".vite", "manifest.json"),
"utf-8",
),
readFileSync(viteManifestPath(router), "utf-8"),
);

const virtualHandlerId = virtualId(handlerModule(router));
Expand Down Expand Up @@ -193,15 +196,7 @@ export async function createBuild(app, buildConfig) {
.map((router) => {
if (router.mode !== "static") {
const bundlerManifest = JSON.parse(
readFileSync(
join(
router.outDir,
router.base,
".vite",
"manifest.json",
),
"utf-8",
),
readFileSync(viteManifestPath(router), "utf-8"),
);
return [router.name, bundlerManifest];
}
Expand Down Expand Up @@ -387,6 +382,16 @@ async function createRouterBuild(app, router) {
routerModePlugin[buildRouter.internals.mode.name]?.(buildRouter) ?? [],
buildTargetPlugin[buildRouter.target]?.(buildRouter) ?? [],
...((await buildRouter.plugins?.(buildRouter)) ?? []),
{
name: "vinxi:build:router:config",
async configResolved(config) {
await app.hooks.callHook("app:build:router:vite:config:resolved", {
vite: config,
router: buildRouter,
app,
});
},
},
],
};

Expand Down Expand Up @@ -543,7 +548,17 @@ const routerModePlugin = {
},
}),
],
spa: () => [
spa: (router) => [
router.handler?.endsWith(".html")
? undefined
: virtual(
{
[handlerModule(router)]: ({ config }) => {
return `export default {}`;
},
},
"handler",
),
spaManifest(),
config("appType", {
appType: "custom",
Expand Down Expand Up @@ -643,6 +658,7 @@ function browserBuild() {
if (env.command === "build") {
invariant(router && router.mode !== "static", "Invalid router");
const { join } = await import("./path.js");
console.log(await getEntries(router));
return {
build: {
rollupOptions: {
Expand Down
7 changes: 2 additions & 5 deletions packages/vinxi/lib/chunks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync } from "fs";
import { join } from "vinxi/lib/path";
import { join, viteManifestPath } from "vinxi/lib/path";

const CHUNK_PREFIX = "c_";

Expand All @@ -18,10 +18,7 @@ function getChunks(app, routerName, modIndex) {

try {
const bundlerManifest = JSON.parse(
readFileSync(
join(router.outDir, router.base, ".vite", "manifest.json"),
"utf-8",
),
readFileSync(viteManifestPath(router), "utf-8"),
);

const chunks = Object.entries(bundlerManifest)
Expand Down
13 changes: 12 additions & 1 deletion packages/vinxi/lib/path.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from "pathe";

export * from "pathe";

export function virtualId(/** @type {string} */ moduleName) {
Expand All @@ -7,5 +9,14 @@ export function virtualId(/** @type {string} */ moduleName) {
export function handlerModule(
/** @type {import("./router-mode").Router} */ router,
) {
return `#vinxi/handler/${router.name}`;
return router.handler?.endsWith(".html")
? router.handler
: `#vinxi/handler/${router.name}`;
}

export function viteManifestPath(
/** @type {import("./router-mode").Router} */ router,
) {
// return join(router.outDir, router.base, ".vite", "manifest.json");
return join(router.outDir, router.base, "manifest.json");
}
2 changes: 2 additions & 0 deletions packages/vinxi/lib/plugins/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function manifest() {
if (!router || !app) {
throw new Error("Missing router or app");
}

console.log(router.name, router.handler);
return {
define: {
"import.meta.env.MANIFEST": `globalThis.MANIFEST`,
Expand Down
2 changes: 1 addition & 1 deletion packages/vinxi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"unenv": "^1.7.4",
"unimport": "^3.2.0",
"unstorage": "^1.9.0",
"vite": "5.0.0-beta.7",
"vite": "4.5.0",
"ws": "^8.13.0",
"zod": "^3.22.2"
},
Expand Down
Loading

0 comments on commit 978b04a

Please sign in to comment.