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";
enum Mode {
Prod,
Dev,
}
const AXUM_ENTRY_POINT: &'static str = r##"
// File automatically generated
// Do not manually change it
@@ -17,6 +22,8 @@ use axum::{routing::get, Router};
use tower_http::services::ServeDir;
use tuono_lib::{ssr, Ssr};
const MODE: &'static = "prod";
// MODULE_IMPORTS
#[tokio::main]
+6
View File
@@ -1,5 +1,11 @@
use axum_bundler::bundle_axum_source;
use std::process::Command;
pub fn run() {
// TODO: Pass "build" argument to update SSR path
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;
pub struct Js;
impl Js {
thread_local! {
pub static SSR: RefCell<Ssr<'static, 'static>> = RefCell::new(
// TODO: handle here dev/prod source
Ssr::from(
read_to_string("./.tuono/server/dev-server.js").unwrap(),
""
+2 -1
View File
@@ -39,7 +39,8 @@
},
"bin": {
"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": [
"dist",
+37 -1
View File
@@ -48,7 +48,6 @@ export function developmentCSRWatch() {
},
build: {
manifest: true,
outDir: '../out',
emptyOutDir: true,
rollupOptions: {
input: './.tuono/client-main.tsx',
@@ -58,3 +57,40 @@ export function developmentCSRWatch() {
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,
},
})
})()
}