-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build in dev + serve web components at top level + adapt hotreload
- Loading branch information
Showing
46 changed files
with
734 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function SomePage() { | ||
return <h1>Some dev page</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Home() { | ||
return <div>Hello world</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export default function Home() { | ||
export default async function Home() { | ||
return <div>Hello world</div>; | ||
} | ||
|
||
Home.suspense = () => { | ||
return <div>Loading...</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
// for testing purposes | ||
export default function User() { | ||
return <div>user</div>; | ||
} |
File renamed without changes.
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,19 @@ | ||
import path from "node:path"; | ||
import fs from "node:fs"; | ||
import getRootDir from "../utils/get-root-dir"; | ||
import logTable from "../utils/log-table"; | ||
import byteSizeToString from "../utils/byte-size-to-string"; | ||
import precompressAssets from "../utils/precompress-assets"; | ||
import getEntrypoints from "../utils/get-entrypoints"; | ||
import getImportableFilepath from "../utils/get-importable-filepath"; | ||
import compileAll from "../utils/compile-all"; | ||
import getConstants from "../constants"; | ||
|
||
const { SRC_DIR, CONFIG } = getConstants(); | ||
const pagesDir = path.join(SRC_DIR, "pages"); | ||
const apiDir = path.join(SRC_DIR, "api"); | ||
let outdir = getRootDir("production"); | ||
const outAssetsDir = path.join(outdir, "public"); | ||
const inAssetsDir = path.join(SRC_DIR, "public"); | ||
const pagesEntrypoints = getEntrypoints(pagesDir); | ||
const apiEntrypoints = getEntrypoints(apiDir); | ||
const middlewarePath = getImportableFilepath("middleware", SRC_DIR); | ||
const layoutPath = getImportableFilepath("layout", SRC_DIR); | ||
const i18nPath = getImportableFilepath("i18n", SRC_DIR); | ||
const entrypoints = [...pagesEntrypoints, ...apiEntrypoints]; | ||
const { IS_PRODUCTION, LOG_PREFIX } = getConstants(); | ||
|
||
if (middlewarePath) entrypoints.push(middlewarePath); | ||
if (layoutPath) entrypoints.push(layoutPath); | ||
if (i18nPath) entrypoints.push(i18nPath); | ||
|
||
// This fix Bun build with only one entrypoint because it doesn't create the subfolder | ||
if (entrypoints.length === 1) { | ||
const subfolder = entrypoints[0].includes(path.join(outdir, "api")) | ||
? "api" | ||
: "pages"; | ||
outdir = path.join(outdir, subfolder); | ||
} | ||
|
||
console.log("🚀 Building your app...\n"); | ||
|
||
const { success, logs, outputs } = await Bun.build({ | ||
entrypoints, | ||
outdir, | ||
root: SRC_DIR, | ||
minify: true, | ||
splitting: true, | ||
plugins: [...(CONFIG?.plugins ?? [])], | ||
}); | ||
|
||
if (!success) { | ||
logs.forEach((log) => console.error(log)); | ||
process.exit(1); | ||
} | ||
|
||
let hasChunk = false; | ||
|
||
logTable( | ||
outputs.map((output) => { | ||
const route = output.path.replace(outdir, ""); | ||
const isChunk = route.startsWith("/chunk-"); | ||
let symbol = "λ"; | ||
|
||
if (isChunk) { | ||
hasChunk = true; | ||
symbol = "Φ"; | ||
} else if (route.startsWith("/middleware")) { | ||
symbol = "ƒ"; | ||
} else if (route.startsWith("/layout")) { | ||
symbol = "Δ"; | ||
} else if (route.startsWith("/i18n")) { | ||
symbol = "Ω"; | ||
} | ||
|
||
return { | ||
Route: `${symbol} ${route}`, | ||
Size: byteSizeToString(output.size, 0), | ||
}; | ||
}), | ||
console.log( | ||
LOG_PREFIX.WAIT, | ||
IS_PRODUCTION | ||
? "🚀 building your Brisa app..." | ||
: "starting the development server...", | ||
); | ||
|
||
console.log("\nλ Server entry-points"); | ||
if (layoutPath) console.log("Δ Layout"); | ||
if (middlewarePath) console.log("ƒ Middleware"); | ||
if (i18nPath) console.log("Ω i18n"); | ||
console.log("Φ JS shared by all \n"); | ||
|
||
if (fs.existsSync(inAssetsDir)) { | ||
// Copy all assets to the build directory | ||
fs.cpSync(inAssetsDir, outAssetsDir, { recursive: true }); | ||
const success = await compileAll(); | ||
const ms = (Bun.nanoseconds() / 1000000).toFixed(2); | ||
|
||
// Precompress all assets | ||
await precompressAssets(outAssetsDir).catch(console.error); | ||
} | ||
if (!success) process.exit(1); | ||
|
||
console.info(`✨ Done in ${(Bun.nanoseconds() / 1000000).toFixed(2)}ms.`); | ||
if (IS_PRODUCTION) console.info(LOG_PREFIX.INFO, `✨ Done in ${ms}ms.`); | ||
else console.info(LOG_PREFIX.INFO, `compiled successfully in ${ms}ms.`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.