Git Product home page Git Product logo

zephyr's Introduction

zephyr

Maintainer: coot zephyr

A tree-shaking tool for PureScript. zephyr takes root terms, finds all terms which are required to evaluate them, and generates code just for them. This is done across all dependencies, and can substantially reduce the size of PureScript bundles. zephyr can also evaluate some expressions (an experimental feature).

Usage

# compile your project
purs compile -g corefn bower_components/purescript-*/src/**/*.purs src/**/*.purs

# run `zephyr`
zephyr -f Main.main

then you can bundle with purs bundle command:

purs bundle -o app.js -m Main dce-output/**/*.js

You can integrate it with other build tools, see below.

You can specify modules as entry points, which is the same as specifying all exported identifiers.

# include all identifiers from Data.Eq module
zephyr Data.Eq

# as above
zephyr module:Data.Eq

# include Data.Eq.Eq identifier of Data.Eq module
zephyr ident:Data.Eq.Eq

# include 'Data.Eq.eq' identifier
zephyr Data.Eq.eq

zephyr reads corefn json representation from the output directory, removes non transitive dependencies of entry points and generates common js modules (or corefn representation) to dce-output directory.

Evaluation of literal expressions

Zephyr can evaluate some literal expressions.

import Config (isProduction)

a = if isProduction
  then "api/prod/"
  else "api/dev/"

will be transformed to

a = "api/prod/"

whenever isProduction is true. This allows to have different development and production environments while still ship a minified code which only contains production code. You may define isProduction in a module under a src-prod directory and include it when compiling production code with pulp build -I src-prod and to have another copy for your development environment under src-dev where isProduction is set to false.

Integration with build tools

zephyr can be integrated with

  • pulp: use pulp build -- -g corefn to compile, and pulp browserify --skip-compile -o dce-output to bundle zephyr's output.
  • parcel
  • spago. See this example. Use spago build --purs-args '--codegen corefn,js' to compile, using spago bundle is currently affected by issue.

Build & Test

cabal build exe:zephyr

To run tests

cabal run zephyr-test

C Libraries

The released binaries are dynamically linked against glibc, so if your system is using musl (like Alpine Linux in docker) or another alternative C library, you will need to compile zephyr from source using ghc on that system.

Comments

The -f switch is not 100% safe. Upon running, zephyr will remove exports from foreign modules that seems to be not used: are not used in PureScript code and seem not to be used in the foreign module. If you simply assign to exports using JavaScript dot notation then you will be fine, but if you use square notation exports[var] in a dynamic way (i.e. var is a true variable rather than a string literal), then zephyr might remove code that shouldn't be removed.

zephyr's People

Contributors

coot avatar dgendill avatar kl0tl avatar rnons avatar toastal avatar

Watchers

 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.