Skip to content

Commit

Permalink
feat(dev): --public-directory option for serving non-Remix assets
Browse files Browse the repository at this point in the history
  • Loading branch information
pcattori committed May 2, 2023
1 parent 68b1f5e commit 9ea371c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export async function dev(
httpHost?: string;
httpPort?: number;
restart?: boolean;
publicDirectory?: string;
websocketPort?: number;
} = {}
) {
Expand Down Expand Up @@ -515,6 +516,7 @@ let resolveDevBuild = async (

type DevServeFlags = DevBuildFlags & {
command: string;
publicDirectory: string;
restart: boolean;
};
let resolveDevServe = async (
Expand Down Expand Up @@ -552,6 +554,12 @@ let resolveDevServe = async (
process.exit(1);
}
}

let publicDirectory =
flags.publicDirectory ??
(dev === true ? undefined : dev.publicDirectory) ??
"public";

let restart =
flags.restart ?? (dev === true ? undefined : dev.restart) ?? true;

Expand All @@ -560,6 +568,7 @@ let resolveDevServe = async (
httpScheme,
httpHost,
httpPort,
publicDirectory,
websocketPort,
restart,
};
Expand Down
6 changes: 6 additions & 0 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
--http-host HTTP(S) host for the dev server. Default: localhost
--http-port HTTP(S) port for the dev server. Default: any open port
--no-restart Do not restart the app server when rebuilds occur.
--public-directory Path to public assets directory relative to Remix project root. Default: public
--websocket-port Websocket port for the dev server. Default: any open port
\`init\` Options:
--no-delete Skip deleting the \`remix.init\` script
Expand Down Expand Up @@ -188,6 +189,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
"--http-host": String,
"--http-port": Number,
"--no-restart": Boolean,
"--public-directory": String,
"--websocket-port": Number,
},
{
Expand Down Expand Up @@ -225,6 +227,10 @@ export async function run(argv: string[] = process.argv.slice(2)) {
flags.httpPort = flags["http-port"];
delete flags["http-port"];
}
if (flags["public-directory"]) {
flags.publicDirectory = flags["public-directory"];
delete flags["public-directory"];
}
if (flags["websocket-port"]) {
flags.websocketPort = flags["websocket-port"];
delete flags["websocket-port"];
Expand Down
1 change: 1 addition & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Dev = {
httpPort?: number;
websocketPort?: number;
restart?: boolean;
publicDirectory?: string;
};

interface FutureConfig {
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-dev/devServer_unstable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export let serve = async (
httpScheme: string;
httpHost: string;
httpPort: number;
publicDirectory: string;
websocketPort: number;
restart: boolean;
}
Expand Down Expand Up @@ -196,7 +197,7 @@ export let serve = async (
maxAge: "1y",
})
)
.use(express.static("public", { maxAge: "1h" }))
.use(express.static(options.publicDirectory, { maxAge: "1h" }))

// handle `broadcastDevReady` messages
.use(express.json())
Expand Down

0 comments on commit 9ea371c

Please sign in to comment.