Got basic page rendering working
This commit is contained in:
parent
9b525f2d05
commit
9a2c2f3a39
2169
package-lock.json
generated
2169
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,12 +5,14 @@
|
|||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/notclickable-jordan/starbase-80"
|
"url": "https://github.com/notclickable-jordan/starbase-80"
|
||||||
},
|
},
|
||||||
"version": "1.1.5",
|
"version": "1.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"start": "npm run build && vite preview"
|
"serve": "vite preview",
|
||||||
|
"start": "node start.js",
|
||||||
|
"stop": "pkill -f node"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/react": "^18.2.45",
|
"@types/react": "^18.2.45",
|
||||||
@ -19,8 +21,10 @@
|
|||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.16",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
|
"npm-run-all": "^4.1.5",
|
||||||
"postcss": "^8.4.32",
|
"postcss": "^8.4.32",
|
||||||
"prettier": "^3.1.1",
|
"prettier": "^3.1.1",
|
||||||
|
"puppeteer": "^21.6.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
|
58
start.js
Normal file
58
start.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { exec } from "child_process";
|
||||||
|
import fs from "fs/promises";
|
||||||
|
import puppeteer from "puppeteer";
|
||||||
|
|
||||||
|
function runNpmCommand(command) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(`npm ${command}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`Error executing command: ${error}`);
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
console.log(`Command output: ${stdout}`);
|
||||||
|
resolve(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderHomePage() {
|
||||||
|
const browser = await puppeteer.launch({
|
||||||
|
headless: true,
|
||||||
|
});
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.goto("http://localhost:4173", { waitUntil: "networkidle0" });
|
||||||
|
|
||||||
|
// Wait for any additional content to load
|
||||||
|
await page.waitForNetworkIdle();
|
||||||
|
|
||||||
|
// Get the rendered HTML content
|
||||||
|
const renderedHTML = await page.content();
|
||||||
|
|
||||||
|
// Save the rendered HTML to a file
|
||||||
|
fs.writeFile("./dist/index.html", renderedHTML);
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runCommands() {
|
||||||
|
try {
|
||||||
|
console.log("Building React site");
|
||||||
|
await runNpmCommand("run build");
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log("Taking snapshot");
|
||||||
|
await renderHomePage();
|
||||||
|
await runNpmCommand("run stop");
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
console.log("Starting web server");
|
||||||
|
await runNpmCommand("run serve");
|
||||||
|
} catch (err) {
|
||||||
|
// Handle errors
|
||||||
|
console.error("An error occurred:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runCommands();
|
Loading…
Reference in New Issue
Block a user