Skip to content

Commit

Permalink
Pass params to serve
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-ok committed Nov 3, 2023
1 parent aa114b6 commit 7a8656b
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions commands/reshowcase
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ const entryPathRelativeTocompiledProjectRoot = path.relative(
entryPath
);

console.log({ compiledProjectRoot });
console.log({ entryPathRelativeTocompiledProjectRoot });

const defaultConfig = {
entryPoints: [entryPath],
bundle: true,
Expand All @@ -114,7 +111,7 @@ const defaultConfig = {
metafile: true,
splitting: true,
treeShaking: true,
logLevel: "info",
logLevel: "warning",
define: {
USE_FULL_IFRAME_URL: JSON.stringify(useFullframeUrl),
},
Expand Down Expand Up @@ -151,8 +148,6 @@ const defaultConfig = {
],
};

console.log({ outputPath });

const config = {
...defaultConfig,
...customConfig,
Expand All @@ -161,33 +156,39 @@ const config = {
};

if (isBuild) {
const durationLabel = "[Reshowcase] Bundle finished. Duration:";
console.log("[Reshowcase] Bundling with esbuild...");
const durationLabel = "[Reshowcase] Build finished. Duration";
console.time(durationLabel);

esbuild
.build(config)
.then((_buildResult) => {
console.timeEnd(durationLabel);
const json = JSON.stringify(_buildResult.metafile);
fs.writeFileSync(
"/Users/denstr/projects/ahrefs-reshowcase/meta.json",
json
);
})
.catch((error) => {
console.error("[Reshowcase] Build failed:", error);
console.error("[Reshowcase] Esbuild build failed:", error);
process.exit(1);
});
} else {
const durationLabel = "[Reshowcase] Watch and serve started. Duration";
console.time(durationLabel);

esbuild
.context(config)
.then((ctx) => {
return ctx.watch().then((_) => ctx);
return ctx.watch().then(() => ctx);
})
.catch((error) => {
console.error("[Reshowcase] Esbuild watch start failed:", error);
process.exit(1);
})
.then((ctx) => {
return ctx.serve();
return ctx.serve({ port: 8000, servedir: outputPath });
})
.then((_serveResult) => {
console.timeEnd(durationLabel);
})
.then((serveResult) => {
console.log({ serveResult });
.catch((error) => {
console.error("[Reshowcase] Esbuild serve start failed:", error);
process.exit(1);
});
}

0 comments on commit 7a8656b

Please sign in to comment.