Coder Social home page Coder Social logo

curioustauseef / jetpack.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vincentdchan/jetpack.js

0.0 0.0 0.0 8.68 MB

A ECMAScript bundler and minifier implemented in C++ aimed at excellent performance.

License: MIT License

CMake 0.48% C++ 89.59% Ruby 3.71% JavaScript 6.21%

jetpack.js's Introduction

Jetpack++

jetpack.js is an extremely fast js bundler and minifier.

jetpack.js a well designed tool. It's modulize into parser and bundler. The parser can be used as a library independently.

Why

Several months ago, I wrote a js parser in C++. Many parsers embedded in other js engine have a lot of dependencies on their runtime. It's very hard to separate them. So I decided to write my own parser. After I finished, I found my parser is almost 10x faster than the common parsers running on Node.js (without heating). But I didn't move on after that. This year(2020), Evan Wallace's project esbuild inspires me. So I decided to write a bundler in C++.

Features

Parser

  • Can be used standalone
  • Implemented in C++ with excellent performance
  • Full support for ECMAScript 2017(ECMA-262 8th Edition)
  • JSON output of sensible syntax tree format as standardized by ESTree project
  • Experimental support for JSX, a syntax extension for React
  • Syntax node location (index-based and line-column)
  • Friendly error message

Bundler

  • Module resolution.
  • Bundle a ES project into a single file.
  • Scope hoisting.
  • Contant folding.
  • Minify the code.

Installation

npm install -g jetpackpp

Or

yarn global add jetpackpp

Usage

Use command line to bundle a js module.

jetpack main.js --out bundle.js

Help command:

$ jetpackpp --help

$ Jetpack++ command line
Usage:
  Jetpack++ [OPTION...] positional parameters

      --tolerant            tolerant parsing error
      --jsx                 support jsx syntax
      --help                produce help message
      --analyze-module arg  analyze a module and print result
      --no-trace            do not trace ref file when analyze module
      --minify              minify the code
      --out arg             output filename of bundle

Use the parser as a standalone library

jetpack.js is built with CMake, so it can be easily integrated to your project.

add_subdirectory(js-parser)
target_include_directories(${PROJECT_NAME} ./js-parser/src)
target_link_libraries(${PROJECT_NAME} PUBLIC js-parser)

Performance

I do the same benchmark provided by esbuild.

My main benchmark approximates a large codebase by duplicating the three.js library 10 times and building a single bundle from scratch, without any caches. For this benchmark, esbuild is 10-100x faster than the other JavaScript bundlers I tested (Webpack, Rollup, Parcel, and FuseBox). The benchmark can be run with make bench-three.

The tests were done on a 6-core 2018 MacBook Pro with 16GB of RAM (similar to esbuild).

Architecture

The code are well commented, please read the code.

Platform

jetpack.js supports all popular system including:

  • macOS
  • Windows 64bit
  • Linux 64bit

jetpack.js's People

Contributors

vincentdchan avatar

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.