mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
feat: scaffold build script
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
""
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
})()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user