Giter VIP home page Giter VIP logo

brfs-babel's Introduction

brfs-babel

experimental

This is like brfs, a browserify transform to inline static files, but built on top of Babel and its AST manipulations. This provides some new features, like ES2015 import support, various additional edge cases, cleaner code output, and source maps.

However, since this is a re-write and work in progress, this has some limitations and currently only supports fs.readFileSync and fs.readdirSync.

Install

npm install brfs-babel --save

Usage

Once installed, you can use it as a replacement for brfs transform:

browserify index.js -t brfs-babel

It will handle ES2015 syntax, so it can be ordered before or after babelify. Or, you can choose to avoid babelify altogether, e.g. if you are targeting a new version of Node/Chrome/FF.

import { readFileSync } from 'fs';
import { join } from 'path';
const src = readFileSync(join(__dirname, 'hello.txt'), 'utf8');

And hello.txt is a text ifle containing the string "Hello, world!".

After transformation:

import { join } from 'path';
const src = 'Hello, World!';

Limitations

The following fs functions are supported:

  • fs.readFileSync(filepath, [enc])
  • fs.readdirSync(filepath)

The following path functions will be evaluated statically when they are found inside the arguments of the above calls:

  • path.join()
  • path.resolve()

Some test cases are failing from brfs. This includes dynamic variables like this:

const path = '/foo.txt';
fs.readFileSync(__dirname + path, 'utf8');

As well as inline CommonJS usage, like this:

require('fs').readFileSync(__dirname + '/foo.txt', 'utf8');

License

MIT, see LICENSE.md for details.

brfs-babel's People

Contributors

mattdesl avatar

Watchers

 avatar  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.