Giter VIP home page Giter VIP logo

bankai's Introduction

bankai

npm version build status downloads js-standard-style

The easiest way to compile JavaScript, HTML and CSS.

We want people to have fun building things for the web. There should be no hurdles between a great idea, and your first prototype. And once you're ready, it should be easy to package it up and share it online. That's Bankai: a tool that helps you build for the web. No configuration, and no hassle - that's our promise.

If this is your first time building something for the web, take a look at choojs/create-choo-app to help get a project setup from scratch โœจ.

Usage

  $ bankai <command> [entry] [options]

  Commands:

    build       compile all files to dist/
    inspect     inspect the bundle dependencies
    start       start a development server

  Options:

    -d, --debug       output lots of logs
    -h, --help        print usage
    -q, --quiet       don't output any logs
    -v, --version     print version

  Examples:

    Start a development server
    $ bankai start index.js

    Visualize all dependencies in your project
    $ bankai inspect index.js

    Compile all files in the project to disk
    $ bankai build index.js

  Running into trouble? Feel free to file an issue:
  https://github.com/choojs/bankai/issues/new

  Do you enjoy using this software? Become a backer:
  https://opencollective.com/choo

Optimizations

Bankai applies lots of optimizations to projects. Generally you won't need to care how we do this: it's lots of glue code, and not necessarily pretty. But it can be useful to know which optimizations we apply. This is a list:

JavaScript

  • bundle-collapser: Remove all pathnames from inside the bundle, and replace them with IDs. This not only makes bundles smaller, it prevents details from your local dev setup leaking.
  • common-shakeify: Remove unused JavaScript code from the bundle. Best known as dead code elimination or tree shaking.
  • unassertify: Remove all require('assert') statements from the code. Only applied for production builds.
  • uglifyify: Minify the bundle.
  • yo-yoify: Optimize choo HTML code so it run significantly faster in the browser.
  • glslify: Adds a module system to GLSL shaders.
  • envify: Allow environment variables to be used in the bundle. Especially useful in combination with minification, which removes unused code paths.
  • brfs: Statically inline calls to fs.readFile(). Useful to ship assets in the browser.

CSS

  • sheetify: extract all inline CSS from JavaScript, and include it in bundle.js.
  • purifyCSS: removes unused CSS from the project.
  • cleanCSS: minify the bundle.

HTML

  • polyfill: preloads polyfill.io, the zero overhead polyfilling service.
  • inline-critical-css: extract all crititical CSS for a page into the <head> of the document. This means that every page will be able to render after the first roundtrip, which makes for super snappy pages.
  • async load scripts: loads scripts in the background using the defer attribute.
  • async load styles: loads styles in the background using the preload attribute.
  • async load styles: preloads fonts in the background using the preload attribute.
  • server render: server renders Choo applications. We're welcome to supporting other frameworks too. PRs welcome!
  • manifest: includes a link to manifest.json so the application can be installed on mobile.
  • viewport: defines the right viewport dimensions to make applications accessible for everyone.
  • theme color: sets the theme color defined in manifest.json so the navigator bar on mobile is styled on brand.
  • title: sets the right title on a page. Either extracts it from the application (choo only, for now) or uses whatever the title is in manifest.json.
  • live reload: during development, we inject a live reload script.

Configuration

The Bankai CLI doesn't take any flags, other than to manipulate how we log to the console. Configuring Bankai is done by modifying package.json.

Bankai is built on three technologies: browserify, sheetify, and documentify. Because these can be configured inside package.json it means that Bankai itself can be configured from there too. Also if people ever decide to switch from the command line to JavaScript, no extra configuration is needed.

{
  "name": "my-app",
  "browserify": {
     "transform": [
       "some-browserify-transform"
     ]
   },
   "sheetify": {
     "transform": [
       "some-sheetify-transform"
     ]
   },
   "documentify": {
     "transform": [
       "some-documentify-transform"
     ]
   }
}

HTTP

Bankai can be hooked up directly to an HTTP server, which is useful when working on full stack code.

var bankai = require('bankai/http')
var http = require('http')
var path = require('path')

var compiler = bankai(path.join(__dirname, 'example'))
var server = http.createServer(function (req, res) {
  compiler(req, res, function () {
    res.statusCode = 404
    res.end('not found')
  })
})

server.listen(8080, function () {
  console.log('listening on port 8080')
})

Events

compiler.on('error', callback(error))

Whenever an internal error occurs.

compiler.on('change', callback(nodeName, edgeName, state))

Whenever a change in the internal graph occurs.

API

compiler = bankai(entry, [opts])

Create a new bankai instance. Takes either an entry file location, or an array of files.

compiler.documents(routename, [opts], done(err, buffer))

Output an HTML bundle for a route. Routes are determined based on the project's router. Pass '/' to get the default route.

  • opts.state: Will be passed the render function for the route, and inlined in the <head> of the body as window.initialState.

compiler.scripts(filename, done(err, buffer))

Pass in a filename and output a JS bundle.

compiler.assets(assetName, done(err, buffer))

Output any other file besides JS, CSS or HTML.

compiler.style(done(err, buffer))

Output a CSS bundle.

compiler.manifest(done(err, buffer))

Output a manifest.json.

compiler.serviceWorker(done(err, buffer))

Output a service worker.

compiler.close()

Close all file watchers.

License

Apache License 2.0

bankai's People

Contributors

yoshuawuyts avatar greenkeeperio-bot avatar toddself avatar marionebl avatar timwis avatar s3ththompson avatar flet avatar goto-bus-stop avatar yerkopalma avatar lrlna avatar f-mer avatar juliangruber avatar bcomnes avatar aknuds1 avatar jakeburden avatar joehand avatar kasperlewau avatar marlun avatar emkay avatar ronnross avatar noffle avatar

Stargazers

 avatar

Watchers

James Cloos avatar Antoine Bluchet avatar  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.