Giter Site home page Giter Site logo

racketscript / racketscript Goto Github PK

View Code? Open in Web Editor NEW
702.0 34.0 31.0 1.22 MB

Racket to JavaScript Compiler

License: MIT License

Racket 69.17% Makefile 0.25% JavaScript 30.52% Shell 0.01% HTML 0.05%
racket compiler javascript programming-language

racketscript's Introduction

RacketScript

MIT licensed Tests ESLint Coverage Status Try Online

Racket Discourse users Racket Discord

RacketScript is an experimental lightweight Racket to JavaScript (ECMAScript 6) compiler. RacketScript aims to leverage both JavaScript and Racket's ecosystem, and make interoperability between them clean and smooth.

RacketScript takes in Racket source files, uses Racket's macro expander to produce Fully Expanded Programs, and then compile these fully expanded programs to JavaScript. RacketScript currently supports only a subset of Racket.

Try RacketScript

You can try RacketScript in your browser at RacketScript Playground.

You may alo be interested in Rackt - An ultrasmall (~70 loc) React wrapper written in RacketScript.

Disclaimer

RacketScript is work-in-progress and is not mature and stable. Several Racket features and libraries are not yet implemented (eg. number pyramid, contracts, proper tail calls, continuations). There are also quite a few missing primitive functions. That said, we encourage experimentation, user feedback, discussions, bug reports and pull requests.

Installation

Following system packages are required:

  • Racket 6.12 or higher
  • NodeJS (14.0 or higher) and NPM
  • Make

Quick Install

RacketScript can be installed using the Racket package manager raco:

raco pkg install racketscript

See Basic Usage to get started.

Install from Github

# Clone RacketScript
git clone [email protected]:racketscript/racketscript.git`
cd racketscript

# Build and install
make setup

If you do not wish to pollute your root NPM directory, you can set a custom global location by changing your npmrc (eg. echo "prefix = $HOME/.npm-packages" >> ~/.npmrc. Then add /prefix/path/above/bin to your PATH.

Basic Usage

RacketScript compiler is named racks.

racks -h # show help

To compile a Racket source file:

# Installs all NPM dependencies and compile file.rkt
racks /path/to/file.rkt

The above command will create a output build directory named js-build, copy RacketScript runtime, copy other support files, install NPM dependencies, compile file.rkt and its dependencies.

The compiled JavaScript modules typically goto one of following three folders:

  • "modules": The normal Racket files.
  • "collects": Racket collects source files.
  • "links": Other third party packages.
  • "dist": Contains sources compiled to ES6 or bundled JavaScript ready for distribution.

Here are few other examples that would come in handy:

# To skip `npm install` step. Useful when building
# for second time.
racks -n /path/to/module-name.rkt

# Run the assembled JavaScript module.
node js-build/modules/module-name.rkt.js

# Use `-b` to format the assembled JavaScript code use `-b`. Assumes
# `js-beautify` is available in `$PATH`.
racks -b /path/to/module-name.rkt

# Override default output directory
racks -d /path/to/output/dir /path/to/module-name.rkt

# Print JavaScript output to stdout
racks --js --js-beautify /path/to/module-name.rkt

By default tail call optimization is turned off. To enable translation of self recursive tail calls to loop, pass --enable-self-tail flag.

racks --enable-self-tail /path/to/source.rkt

Browser

Most browsers can load RacketScript modules directly without any external dependencies <script type="module" src="path/to/module.rkt.js"></script>.

Module Bundler (Webpack)

For deployment, you may want to bundle all generated modules into single JavaScript file. RacketScript can generate some boiler-plate for using Webpack/Babel, however we recommend you to use your own configuration.

# Use `--target` or `-t` flag.
racks --target webpack /path/to/source.rkt

# Call webpack to bundle in `js-build` directory. Will produce
# single JavaScript bundle in `js-build/dist` directory.
npx webpack

Contributing to RacketScript

Please read Contribution Guidelines.

Troubleshooting

Please read the Troubleshooting Wiki.

Related Work

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.