babelμ 첫λ²μ§Έ 컀λ°μμλΆν° μ½λλ₯Ό λΆμνκ³ μ΄λ»κ² ꡬνλμ΄μκ³ λμνλ μ리λ₯Ό μμλ΄ μλ€.
/
/lib
/6to5
/templates
/transformers
/traverse
/browserify.js
/middleware.js
/node.js
/transform.js
/util.js
/package.json
ν¨ν€μ§μ λ΄μ©μ μ μν©λλ€. μνΈλ¦¬ νμΌμ΄ ./lib/6to5/node.js
μμ μ μ μμ΅λλ€.
ASTμ λ Έλ μ€ es6μ λ¬Έλ²μΌλ‘ μμ±λ κ²μ es5μ λ¬Έλ²μ λ§λ λ Έλλ‘ λ³νν΄μ£Όλ ν¨μκ° μ μΈλμ΄ μμ΅λλ€.
μλ§ λ²μ©μ μΌλ‘ μ¬μ©νκΈ° μν΄ μ μλ λ―Έλ€μ¨μ΄νμΌμ΄λΌκ³ μκ°ν©λλ€.
babel
μ μνΈλ¦¬ μ§μ μ
λλ€. ν¨ν€μ§μμ μ¬μ©λλ ν¨μλ₯Ό μ μΈν©λλ€.
es6 λ¬Έλ²μΌλ‘ μ μλ μ½λλ₯Ό es5 λ¬Έλ²μΌλ‘ μ μλ μ½λλ‘ λ³ννλ ν¨μκ° μ μΈλμ΄ μμ΅λλ€. es6 λ¬Έλ²μ μ½λλ₯Ό ASTλ‘ λ³ννλ ν¨μλ ./lib/6to5/transformers
μ μ μλμ΄ μμ΅λλ€. λ€λ§ ASTλ‘λΆν° ECMAScript μ½λ μμ±μ μΈλΆ ν¨ν€μ§μ μμ‘΄νκ³ μμ΅λλ€.
νμ λ±μ ν¨μκ° κ΅¬νλμ΄ μμ΅λλ€. μ°Έκ³ λ‘ νμμμλ μΈλΆ λͺ¨λ(esprima
)μ μ¬μ©ν©λλ€.
μλλ μ repoμ readme νμΌ λ΄μ©μ λλ€.
6to5 turns ES6 code into vanilla ES5, so you can use ES6 features today.
6to5 is:
- Fast - 10x faster than Traceur.
- Compact - maps directly to the equivalent ES5.
- Easy - with Browserify support, Node API, Connect Middleware and a CLI.
- Concise - we do not pollute any scope with unneccesary variables or functions declarations.
Name | Implemented |
---|---|
Arrow functions | β |
Classes | β |
Default parameters | β |
Spread | β |
Block binding | β |
Property method assignment | β |
Rest parameters | β |
Template literals | β |
Modules | β |
Destructuring assignment | |
Generators |
$ npm install -g 6to5
Compile the file script.js
and output it to script-compiled.js
.
$ 6to5 script.js -o script-compiled.js
Compile the entire src
directory and output it to the lib
directory.
$ 6to5 src -d lib
Compile the file script.js
and output it to stdout.
$ 6to5 script.js
var to5 = require("6to5");
to5.transform("code();");
to5.transformFileSync("script.js");
to5.transformFile("script.js", function (err, data) {
});
to5.transform("code();", {
// List of transformers to EXCLUDE
// See `features` for valid names.
blacklist: [],
// List of transformers to ONLY use.
// See `features` for valid names.
whitelist: [],
// Append source map and comment to bottom of returned output.
sourceMap: false,
// Filename for use in errors etc.
filename: "unknown",
// Format options
// See https://github.com/Constellation/escodegen/wiki/API for options.
format: {}
});
All subsequent files required by node will be transformed into ES5 compatible code.
require("6to5/register");
var to5 = require("6to5");
app.use(6to5.middleware({
transform: {
// options to use when transforming files
},
src: "assets",
dest: "cache"
}));
app.use(connect.static("cache"));
$ browserify script.js -t 6to5/browserify --outfile bundle.js
var to5 = require("6to5");
browserify()
.transform(to5.browserify)
.require("script.js", { entry: true })
.bundle({ debug: true })
.pipe(fs.createWriteStream("bundle.js"));