Giter Site home page Giter Site logo

ftdebugger / es6ify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thlorenz/es6ify

0.0 2.0 0.0 1.45 MB

browserify v2 transform to compile JavaScript.next (ES6) to JavaScript.current (ES5) on the fly.

Home Page: http://thlorenz.github.com/es6ify/

License: MIT License

es6ify's Introduction

es6ify build status

NPM

browserify v2 transform to compile JavaScript.next (ES6) to JavaScript.current (ES5) on the fly

browserify()
  .add(es6ify.runtime)
  .transform(es6ify)
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle({ debug: true })
  .pipe(fs.createWriteStream(bundlePath));

Find the full version of this example here.

Installation

npm install es6ify

What You Get

screenshot

Try it live

Table of Contents generated with DocToc

API

es6ify

Returns a transform with default file pattern and standard error stream.

browserify()
  .add(require('es6ify').runtime)
  .transform(require('es6ify'))
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle({ debug: true })
  .pipe(fs.createWriteStream(bundlePath));

es6ify.configure(filePattern : Regex)

Returns a es6 transform with custom file pattern and standard error stream.

The default file pattern includes all JavaScript files, but you may override it in order to only transform files coming from a certain directory, with a specific file name and/or extension, etc.

By configuring the regex to exclude ES5 files, you can optimize the performance of the transform. However transforming ES5 JavaScript will work since it is a subset of ES6.

browserify()
  .add(require('es6ify').runtime)
   // compile all .js files except the ones coming from node_modules
  .transform(require('es6ify').configure(/^(?!.*node_modules)+.+\.js$/))
  .require(require.resolve('./src/main.js'), { entry: true })
  .bundle({ debug: true })
  .pipe(fs.createWriteStream(bundlePath));

es6ify.runtime

Returns runtime necessary to support ES6 features and therefore needs to be added to the bundle like in the example above.

Caching

When es6ify is run on a development server to help generate the browserify bundle on the fly, it makes sense to only recompile ES6 files that changed. Therefore es6ify caches previously compiled files and just pulls them from there if no changes were made to the file.

Source Maps

es6ify instructs the traceur transpiler to generate source maps. It then inlines all original sources and adds the resulting source map base64 encoded to the bottom of the transformed content. This allows debugging the original ES6 source when using the debug flag with browserify.

If the debug flag is not set, these source maps will be removed by browserify and thus will not be contained inside your production bundle.

Supported ES6 features

arrayComprehension

arrowFunctions

example

classes

example

defaultParameters

example

destructuring

example

forOf

example

propertyMethods

propertyNameShorthand

templateLiterals

restParameters

example

spread

example

generatorComprehension

generators

example

blockBinding

The block binding let is implemented in ES5 via try/catch blocks which may affect performance.

Unsupported ES6 Features

modules

I recommend to use require instead since that integrates better with browserify.

If you want to use ES6 modules, you need to compile all files that use them into one file since inlining them is the only way to make this work in ES5. You can then browserify.add that file and therefore wouldn't need es6ify.

Compiling a single file makes caching impossible and will lead to longer bundle times when used on the development server to bundle on the fly.

Bitdeli Badge

es6ify's People

Contributors

bitdeli-chef avatar domenic avatar forbeslindesay avatar thlorenz avatar

Watchers

 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.