Skip to content

Commit

Permalink
Merge pull request #423 from nksaraf/dev-plugin-v2
Browse files Browse the repository at this point in the history
feat: nitro plugin support in dev
  • Loading branch information
nksaraf authored Dec 2, 2024
2 parents 95eeef1 + 3b9e68c commit a62ff02
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-emus-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vinxi": patch
---

feat: nitro plugin support in dev
2 changes: 1 addition & 1 deletion .changeset/tender-coats-repeat.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@fake-scope/fake-pkg": patch
"vinxi": minor
---

chore: bump nitro to v2.10.4, h3 to v13.0
17 changes: 15 additions & 2 deletions packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mkdir, rm, rmdir } from "fs/promises";
import { createRequire } from "module";
import { build, copyPublicAssets, createNitro, prerender } from "nitropack";
import { isRelative } from "ufo";

import { readdirSync, statSync, writeFileSync } from "node:fs";
import { pathToFileURL } from "node:url";
Expand All @@ -12,7 +13,13 @@ import invariant from "./invariant.js";
import { c, consola, log, withLogger } from "./logger.js";
import { viteManifestPath } from "./manifest-path.js";
import { createSPAManifest } from "./manifest/spa-manifest.js";
import { handlerModule, join, relative, virtualId } from "./path.js";
import {
handlerModule,
isAbsolute,
join,
relative,
virtualId,
} 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 @@ -124,7 +131,13 @@ export async function createBuild(app, buildConfig) {
fileURLToPath(new URL("./app-fetch.js", import.meta.url)),
fileURLToPath(new URL("./app-manifest.js", import.meta.url)),
"$vinxi/chunks",
...(app.config.server.plugins ?? []),
...(app.config.server.plugins ?? []).map((plugin) =>
isRelative(plugin)
? plugin
: isAbsolute(plugin)
? plugin
: require.resolve(plugin, { paths: [app.config.root] }),
),
],
buildDir: ".vinxi",
handlers: [
Expand Down
20 changes: 16 additions & 4 deletions packages/vinxi/lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,28 @@ export async function createDevServer(
// }

// Running plugins manually
const devViteServer = await import("vite").then(({ createServer }) =>
createServer({}),
);

const plugins = [
new URL("./app-fetch.js", import.meta.url).href,
new URL("./app-manifest.js", import.meta.url).href,
fileURLToPath(new URL("./app-fetch.js", import.meta.url)),
fileURLToPath(new URL("./app-manifest.js", import.meta.url)),
...(app.config.server.plugins ?? []),
];

for (const plugin of plugins) {
const { default: pluginFn } = await import(plugin);
await pluginFn(devApp);
const { default: pluginFn } = await devViteServer.ssrLoadModule(plugin);
try {
await pluginFn(devApp);
} catch (error) {
console.error(`Error running plugin ${plugin}`);
console.error(error);
}
}

await devViteServer.close();

return {
...devApp,
listen: async () => {
Expand Down

0 comments on commit a62ff02

Please sign in to comment.