feat: scaffold build script

This commit is contained in:
Valerio Ageno
2024-05-23 22:32:43 +02:00
parent 322908145e
commit 5a30f36eb0
5 changed files with 54 additions and 2 deletions
+7
View File
@@ -7,6 +7,11 @@ use std::path::PathBuf;
const ROOT_FOLDER: &'static str = "src/routes"; const ROOT_FOLDER: &'static str = "src/routes";
enum Mode {
Prod,
Dev,
}
const AXUM_ENTRY_POINT: &'static str = r##" const AXUM_ENTRY_POINT: &'static str = r##"
// File automatically generated // File automatically generated
// Do not manually change it // Do not manually change it
@@ -17,6 +22,8 @@ use axum::{routing::get, Router};
use tower_http::services::ServeDir; use tower_http::services::ServeDir;
use tuono_lib::{ssr, Ssr}; use tuono_lib::{ssr, Ssr};
const MODE: &'static = "prod";
// MODULE_IMPORTS // MODULE_IMPORTS
#[tokio::main] #[tokio::main]
+6
View File
@@ -1,5 +1,11 @@
use axum_bundler::bundle_axum_source; use axum_bundler::bundle_axum_source;
use std::process::Command;
pub fn run() { pub fn run() {
// TODO: Pass "build" argument to update SSR path
bundle_axum_source(); bundle_axum_source();
println!("Build JS source");
let mut vite_build = Command::new("./node_modules/.bin/tuono-build-prod");
let _ = &vite_build.output().unwrap();
} }
+2
View File
@@ -3,9 +3,11 @@ use std::cell::RefCell;
use std::fs::read_to_string; use std::fs::read_to_string;
pub struct Js; pub struct Js;
impl Js { impl Js {
thread_local! { thread_local! {
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new( pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
// TODO: handle here dev/prod source
Ssr::from( Ssr::from(
read_to_string("./.tuono/server/dev-server.js").unwrap(), read_to_string("./.tuono/server/dev-server.js").unwrap(),
"" ""
+2 -1
View File
@@ -39,7 +39,8 @@
}, },
"bin": { "bin": {
"tuono-dev-ssr": "./bin/dev-ssr.js", "tuono-dev-ssr": "./bin/dev-ssr.js",
"tuono-dev-watch": "./bin/watch.js" "tuono-dev-watch": "./bin/watch.js",
"tuono-build-prod": "./bin/build-prod.js"
}, },
"files": [ "files": [
"dist", "dist",
+37 -1
View File
@@ -48,7 +48,6 @@ export function developmentCSRWatch() {
}, },
build: { build: {
manifest: true, manifest: true,
outDir: '../out',
emptyOutDir: true, emptyOutDir: true,
rollupOptions: { rollupOptions: {
input: './.tuono/client-main.tsx', input: './.tuono/client-main.tsx',
@@ -58,3 +57,40 @@ export function developmentCSRWatch() {
await server.listen() await server.listen()
})() })()
} }
export function buildProd() {
;(async () => {
await build({
...BASE_CONFIG,
manifest: true,
build: {
outDir: '../out/client',
},
emptyOutDir: true,
rollupOptions: {
input: './.tuono/client-main.tsx',
},
})
await build({
...BASE_CONFIG,
build: {
ssr: true,
minify: false,
outDir: '../out/server',
emptyOutDir: true,
rollupOptions: {
input: './.tuono/server-main.tsx',
output: {
entryFileNames: 'prod-server.js',
format: 'iife',
},
},
},
ssr: {
target: 'webworker',
noExternal: true,
},
})
})()
}