Skip to content

Commit

Permalink
Merge pull request #359 from XiNiHa/feat/vite-mode
Browse files Browse the repository at this point in the history
Add support for Vite --mode
  • Loading branch information
ryansolid authored Sep 3, 2024
2 parents 8383755 + 1b4381a commit cb790e1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-boats-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vinxi": patch
---

Add support for Vite --mode
5 changes: 5 additions & 0 deletions packages/vinxi/bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const command = defineCommand({
type: "string",
description: "Path to config file (default: app.config.js)",
},
mode: {
type: "string",
description: "Vite mode",
}
},
subCommands: () => ({
dev: {
Expand Down Expand Up @@ -419,6 +423,7 @@ const command = defineCommand({
const { fetchModule, createServer } = await import("vite");
const { ViteRuntime, ESModulesRunner } = await import("vite/runtime");
const server = await createServer({
mode: context.args.mode,
resolve: {
alias: {
"vinxi/sh": fileURLToPath(
Expand Down
5 changes: 5 additions & 0 deletions packages/vinxi/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { resolveRouterConfig, routerSchema } from "./router-modes.js";
string;
server?: Omit<import('nitropack').NitroConfig, 'handlers' | 'devHandlers' | 'publicAssets' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
root?: string
mode?: string
}} AppOptions */

/** @typedef {{
Expand All @@ -23,6 +24,7 @@ import { resolveRouterConfig, routerSchema } from "./router-modes.js";
server: Omit<import('nitropack').NitroConfig, 'handlers' | 'devHandlers' | 'publicAssets' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
routers: import("./router-mode.js").Router[];
root: string;
mode?: string;
};
addRouter: (router: any) => App;
addRouterPlugins: (apply: (router: import("./router-mode.js").Router) => boolean, plugins: () => any[]) => void;
Expand All @@ -45,6 +47,7 @@ export function createApp({
name = "vinxi",
server = {},
root = process.cwd(),
mode,
} = {}) {
const hooks = createHooks();
hooks.afterEach((result) => {
Expand Down Expand Up @@ -96,6 +99,7 @@ export function createApp({
routers: parsedRouters,
server,
root,
mode,
},
index,
),
Expand All @@ -113,6 +117,7 @@ export function createApp({
routers: resolvedRouters,
server,
root,
mode,
};

hooks.callHook("app:config-resolved", { config });
Expand Down
1 change: 1 addition & 0 deletions packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ async function createRouterBuild(app, router) {
await createViteBuild({
app: app,
root: router.root,
mode: app.config.mode,
build: {
ssr: true,
ssrManifest: true,
Expand Down
1 change: 1 addition & 0 deletions packages/vinxi/lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function createViteHandler(router, app, serveConfig) {
force: serveConfig.force,
},
dev: serveConfig,
mode: app.config.mode,
router,
app,
server: {
Expand Down
2 changes: 2 additions & 0 deletions packages/vinxi/lib/load-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ async function loadFile(
/**
*
* @param {string | undefined} configFile
* @param {{ mode?: string }} args
* @returns {Promise<import("./app.js").App | undefined>}
*/
export async function loadApp(configFile = undefined, args = {}) {
Expand Down Expand Up @@ -178,6 +179,7 @@ export async function loadApp(configFile = undefined, args = {}) {
);

const app = createApp({
mode: args.mode,
routers: [
{
name: "public",
Expand Down

0 comments on commit cb790e1

Please sign in to comment.