Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/theiyd/mini-bundler

A simple implementation of a JS bundler
https://github.com/theiyd/mini-bundler

bundler javascript tooling

Last synced: 3 days ago
JSON representation

A simple implementation of a JS bundler

Awesome Lists containing this project

README

        

# Minibundler

The project is a basic, naive implementation of a real-world JavaScript bundler. The purpose of this repo is to understand and learn the underlying mechanisms, structure and processes.

The AST is generated by SWC [(speedy-web-compiler)](https://swc.rs/docs/usage/core#parse) to scope the learning to only bundling.

### What does it do ?

All the JavaScript files with a single entry point are bundled into one file which can be executed in a Node runtime.

- Dependency resolution
- AST
- Bundle to one

It uses the Rollup style to bundle i.e build the dependency graph, and walk back by starting from the last vertex, resolving the dependencies by replacing with the imported code.

### To get set up

```bash
npm i

npm run start
```

### Limitations

As I mentioned, it's a toy project and it comes with things it does not support as of now:

- Dependency resolution might not be perfect.
- `module.exports` does not work alongwith inline default exports.
- Bundled code is not cleaned up as it just does a manual merge.
- Circular dependencies do not work.
- Same named variables/functions are not renamed like Rollup.
- More stuff which maybe I haven't come across yet!

### Testing

```bash
npm test
```