TС39
Может внести член TC39 или
зарегистрированный контрибьютор TC39
Допустим, но зачем?
Сравните
cкорость
Наши инструменты
Can we?
Yes, we can!
Транспайлеры
Babel.js
npm init
npm install --save grunt
npm install --save grunt-babel
npm install --save babel-preset-es2015
npm install --save load-grunt-tasks
vi Gruntfile.js// Gruntfile.js
module.exports = function (grunt) {
require("load-grunt-tasks")(grunt);
grunt.initConfig (
//…
);
grunt.registerTask("default", ["babel"]);
};"// Gruntfile.js, Задача
{babel: {
options: {
sourceMap: true,
presets: ['babel-preset-es2015']
},
dist: {files: [
//…
]}}}// Gruntfile.js, Пути к файлам, статические
{
'js/script_1.js': 'js/source/script_1.js',
'js/script_2.js': 'js/source/script_2.js'
}// Gruntfile.js, Пути к файлам, динамические
{
expand: true,
cwd: 'js/source/',
src: ['**/*.js'],
dest: 'js/'
}# package.info
…
"scripts": {
"build": "grunt --verbose"
},
…npm run buildnpm install --save grunt-contrib-watch// Gruntfile.js, Задача
watch: {
scripts: {
files: ['js/source/**/*.js'],
tasks: ['babel'],
}
}
// …
grunt.registerTask("dev", ["babel","watch"]);# package.info
# …
"scripts": {
"build": "grunt --verbose"
"watch": "grunt watch --verbose"
},
# …npm run watchnpm init
npm install --save gulp
npm install --save gulp-sourcemaps
npm install --save gulp-babel
npm install --save babel-preset-es2015
vi gulpfile.js// gulpfile.js
var gulp = require("gulp");
var sourcemaps = require("gulp-sourcemaps");
var babel = require("gulp-babel");
gulp.task("babel", function () {
return gulp.src("js/source/**/*.js")
.pipe(sourcemaps.init())
.pipe(babel({presets: ['es2015']}))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("js/"));
});
gulp.task("default", ["babel"]);# package.info
# …
"scripts": {
"build": "gulp --verbose"
},
# …npm run buildgulp.task("watch", ["babel"], function() {
var watcher = gulp.watch('js/source/**/*.js',
['babel']);
});# package.info
# …
"scripts": {
"build": "gulp --verbose"
"watch": "gulp watch --verbose"
},
# …npm run watch// moses.js
class Moses {
constructor () {
let myPeopleGo = "Moses";
alert(myPeopleGo);
}
}
new Moses;aja project add-module vaimo/themebuilder:dev-develop
cd ./vendor/vaimo/themebuilder/
hg update 0d1c77d
nvm install 6.3.1
npm cache clean
npm install
qrcscript.es6npm run gulp
qrcm2:root/
package.json
Gruntfile.jsnpm install
npm install --save grunt-babel
npm install --save babel-preset-es2015composer require demo-vendor/demo-m2-themem2:root/
dev/
tools/
grunt/
configs/
themes.js
combo.js
babel.js// themes.js
dm2: {
area: 'frontend',
name: 'demo-vendor/demo-m2-theme',
locale: 'en_US',
files: ['css/styles-m','css/styles-l'],
dsl: 'less'
// …
},// themes.js, конфиг babel.js
babelFiles: [{
expand: true,
cwd: 'js/source/',
src: ['**/*.js'],
dest: 'js/'
}]// combo.js
var theme = require('./themes'),
path = require('./path'),
refine_path = function (theme, file_path) {
return path.pub +
theme.area + '/' +
theme.name + '/' +
theme.locale + '/' +
file_path;
};// combo.js
babelFiles: function (themeName) {
var es6Files = [],
ourTheme = theme[themeName],
files = ourTheme.babelFiles;
for (var i = 0; i < files.length; i++) {
if (typeof files[i].src == "undefined") {
// static file mapping
} else {
// dynamic file mapping
}
}
return es6Files;
},// combo.js, static file mapping
var path_collection = {};
for (var target in files[i]) {
path_collection[refine_path(ourTheme, target)] =
refine_path(ourTheme, files[i][target]);
}
es6Files.push(path_collection);// combo.js, dynamic file mapping
files.cwd = refine_path(ourTheme, files.cwd);
files.dest = refine_path(ourTheme, files.dest);
es6Files.push(files);// babel.js, переменные
'use strict';
var combo = require('./combo'),
themes = require('./themes'),
_ = require('underscore'),
themeOptions = {};// babel.js, пути к файлам
_.each(themes, function(theme, name) {
if (typeof theme.babelFiles != "undefined") {
themeOptions[name] = {
files: combo.babelFiles(name)
};
}
});// babel.js, настройки транспайлера
var babelOptions = {
options: {
sourceMap: true,
presets: ['babel-preset-es2015']
}
};// babel.js, экспорт конфигурации
module.exports = _.extend(themeOptions, babelOptions);php bin/magento setup:static-content:deploy
grunt less:dm2
grunt babel:dm2
php bin/magento cache:flushАнтон Немцев
@silentimp
http://silentimp.info/
anton.nemtsev@vaimo.com
skype: ravencry