Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports ES2015 modules #10

Closed
wants to merge 7 commits into from
Closed

Supports ES2015 modules #10

wants to merge 7 commits into from

Conversation

alex-kinokon
Copy link

This pull requests adds the cli option --ecma-version to support producing ES6 outputs for use of either modern browsers or for ES6 module aware transpilers, such as rollup and Webpack 2.

@antonmedv
Copy link
Owner

Hi,

Great PR, but what is purpose of compiling to es2015?

PS it's better call it es2015 =)

@Mevrael
Copy link

Mevrael commented Jul 3, 2016

@Elfet

what is purpose of compiling to es2015?

Because it is a current standard for a year. I don't know what AMD, commonJS and whatever else is, W3C has no connection to them.

JS = ES2015 and in 2016 you have to use it.

@alex-kinokon
Copy link
Author

alex-kinokon commented Jul 3, 2016

@Elfet Most realistically, bundlers like rollup can aggressively analyze and remove unused codes and collapse all scopes into a single one, greatly improving its performance. With CommonJS bundlers can only play it safe and wrap everything up. For Tumblr, walking through the dependency tree takes a whopping 400ms. This is not a issue with bundled ES2015 modules because there is no tree to begin with.

ES2015 modules also supports circular dependencies and live binding for imported/exported variables, which is always a plus.

@alex-kinokon
Copy link
Author

Some note: my browser (Chrome) isn’t very happy with --> because it is recognized as the end of comment.

@alex-kinokon alex-kinokon changed the title Supports ES6 modules Supports ES2015 modules Jul 3, 2016
@antonmedv
Copy link
Owner

antonmedv commented Jul 4, 2016

I'm going to merge this PR, but i'd like to make a few changes before: like naming conventions and option param name (i'd like to see what other libraries like webpack or typescript using for same purpose).

Some note: my browser (Chrome) isn’t very happy with --> because it is recognized as the end of comment.

This is some kind of easter eggs do you have problems with it?

@alex-kinokon
Copy link
Author

@Elfet My test suites wouldn’t run, but that’s it.

@antonmedv
Copy link
Owner

@alexlur do you run test with testem command?

@alex-kinokon
Copy link
Author

@Elfet Yeah. Is it a bug with testem itself?

@antonmedv
Copy link
Owner

What king of bug you getting? Because it's work good for me.

@antonmedv
Copy link
Owner

Option Type Default Comment
--target, -t string "es5" Specify ECMAScript target version: 'es5', 'es6' or 'es2015'.

@alex-kinokon
Copy link
Author

@Elfet Looks good.

"babel-preset-es2015": "^6.9.0",
"jasmine": "^2.4.1",
"jison": "^0.4.17",
"phantomjs-prebuilt": "^2.1.7",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't run tests without explicitly installing phantomjs.

@antonmedv
Copy link
Owner

I'n going to implement it myself based if this pr.

@Mevrael
Copy link

Mevrael commented Jul 7, 2016

I believe '-t' option is not yet in master?

Also could you please make a main monkberry.js itself with ES6 export so it would be possible to import it as ES6 with Rollup like there is lodash-es repo for example?

node build.js script:

var rollup = require('rollup');
var npm = require('rollup-plugin-node-resolve');

rollup.rollup({
    entry: 'app.js',
    plugins: [
        npm(),
    ]
}).then(function(bundle) {
    return bundle.write({
        dest: 'dist/app.js'
    });
}).then(function() {
    console.log('Rollup bundle created');
}).catch(function(e) {
    console.error(e);
});

I have manually added ES6 imports/exports to monkberry and compiled template. Everything worked fine.

app.js

import Monkberry from './monkberry';
import Template from './view';

const view = Monkberry.render(Template, document.body);

view.update({title: 'Test'});

template.monk compiled into view.js via monkberry template.monk -o view.js

<div>
    <h1>{{ title }}</h1>
</div>

It also would be very nice to have a JavaScript API to compile templates via build scripts and not only via CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants