npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fray

v0.0.2

Published

Fray - A simple JavaScript Module Bundler

Downloads

12

Readme

Fray - A simple JavaScript Module Bundler

🚧 This package is in very early development and does not cater for most use cases. 🚧

Overview

Fray is a JavaScript module bundler designed to streamline the process of managing and bundling JavaScript files and their dependencies. It leverages Jest Haste Map for efficient file management and dependency resolution, and uses Babel for code transformation. This document outlines the current features of Fray and provides a roadmap for future enhancements.

Current Features

  1. Module Bundling:
    • Fray collects and resolves JavaScript modules, transforming and bundling them into a single output file.
    • Uses Jest Haste Map to build a dependency graph and resolve modules.
  2. Code Transformation:
    • Transforms JavaScript code using Babel, specifically with the @babel/plugin-transform-modules-commonjs plugin to convert ES6 modules to CommonJS.
  3. Custom Module Loader:
    • Implements a custom require function to load and execute bundled modules.
    • Supports caching to avoid redundant module loading.
  4. Command-Line Interface:
    • Supports specifying an entry point via command-line arguments.
    • Allows outputting the bundled code to a specified file.

Getting Started

Prerequisites

  • Node.js
  • npm or yarn

Installation

Clone the repository and install the dependencies:

git clone https://github.com/your-username/fray.git
cd fray
npm install

Usage

To bundle your project, run:

node index --entrypoint path/to/your/entry/file.js --output path/to/output/bundle.js

Code Structure

  • index.ts: Main script that handles module resolution, transformation, and bundling.
  • worker.ts: Worker script that handles code transformation using Babel.
  • require.js: Custom module loader template used in the output bundle.

Example

Assuming your project structure is as follows:

project/
├── src/
│   ├── index.js
│   ├── moduleA.js
│   └── moduleB.js
├── bundler.js
└── require.js

Run the bundler:

node bundler.js --entrypoint ./src/index.js --output ./dist/bundle.js

Roadmap

  1. Add a -minify Flag:
    • Integrate a minifier like terser to minify each individual file in the bundle.
  2. Add a Cache:
    • Implement a caching mechanism to store transformed files and only re-compile files that have changed.
  3. Generate Source Maps (Medium):
    • Learn about source maps and generate the corresponding .map file for the bundle to improve debugging.
  4. Add a -dev Option (Medium):
    • Start an HTTP server that serves the bundled code through an HTTP endpoint for development purposes.
  5. Automatic Re-Bundling (Medium):
    • Utilize Jest Haste Map’s watch function to listen for file changes and automatically re-bundle the project.
  6. Switch to ESM with Import Maps (Advanced):
    • Learn about Import Maps and transition the bundler from CommonJS to native ESM.
  7. Hot Reloading (Advanced):
    • Implement hot reloading by adjusting the runtime to update modules by de-registering and re-running the module and its dependencies.

Contribution

We welcome contributions to Fray! Please follow the contributing guidelines to get started.

License

Fray is licensed under the MIT License.