Giter Club home page Giter Club logo

mach's People

Contributors

alshdavid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dra11y

mach's Issues

Bundling browser JS from Rust

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.