alshdavid / mach Goto Github PK
View Code? Open in Web Editor NEWThe bundler from down under
License: MIT License
The bundler from down under
License: MIT License
Hi @alshdavid, I came across your article here: https://www.davidalsh.com/posts/writing-a-bundler-part-1/ and was hoping to read parts 2 and 3, but noticed that the repo at link to source has been removed.
I guess this is a feature proposal or for your thoughts on it.
I am building a specific web testing suite in Rust using thirtyfour or chromiumoxide. Many of my testing tools run as JavaScript in the browser context, and I am building specific tooling around them that must run in-browser. This testing suite is deployed to serverless workers in the cloud using Docker. (My huge test suite is currently in TypeScript compiled with Bun but this presents longevity and maintenance problems that seem to keep popping up every time a dependency or Bun is updated, not to mention having to bundle node_modules for the entire workspace, the lack of tree-shaking in Bun -- can't even go back to Node.js because I've used Bun's specific importing "magic" -- and things generally breaking every other time I deploy -- hence I'm rebuilding everything in Rust.) Therefore, I am writing all of my in-browser test tooling code in TypeScript, and wish to type-check, transpile, and bundle it at compile time in build.rs
in my Rust project. If there's a TypeScript error in my code, the build should fail. I then intend to use rust-embed to load the transpiled JavaScript bundle files statically into my single binary that will run in a Docker container.
Am I crazy, or the first/only one, who wants to bundle JavaScript from Rust code, instead of a separate pre-compiled CLI tool? I've looked at all projects (swc, deno, turbopack) and none of them have friendly APIs to just bundle a package from Rust code. Why is this? You'd think a Rust API would be a 1st-class citizen among Rust developers!
Fortunately, I came across your crate here, and was able to fork it and add two lines of code to mach/src/lib.rs
:
pub mod cmd;
pub mod platform;
This made these modules public and I was able to test it like this:
use std::path::Path;
use mach::cmd::build::{main as build, BuildCommand};
fn main() {
let entry_point = Path::new("./index.ts").to_path_buf();
let out_folder = Path::new("./build").to_path_buf();
let command = BuildCommand {
entry: Some(vec![entry_point]),
out_folder,
clean: true,
no_optimize: false,
bundle_splitting: false,
threads: None,
node_workers: None,
debug: true,
};
let _ = build(command);
}
What are your thoughts on this? Should the resulting bundles work in web? (I'm new to Rust and swc is pretty complex.) Are you intending to develop/maintain this crate further and, if so, would you be willing to expose your API a bit more so that custom bundlers can be built on it in Rust?
I would consider putting these requests into swc, deno, turbo but I get the impression those projects have other priorities, and the swc maintainer has moved on to Vercel and claims their bundler isn't even being maintained.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.