Code Monkey home page Code Monkey logo

Comments (10)

christophehurpeau avatar christophehurpeau commented on June 6, 2024

Hello !
Indeed, to support async functions, you can add stage-0 or stage-1 or modern-browsers-stage-1.

It doesn't compile everything the same as es2015, but safari 9 doesn't supports classes, so it does transform classes. You can see all features supported in the compatibility table. I can't wait for safari 10 ! =)
You can also choose to support only latest firefox and chrome.

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

Ah, for sure. The problem is I'm making a library (as opposed to an app), so I guess I need to compile the classes then since I want it to be usable everywhere.

Hmmm, but I am using my library in some apps. Maybe I can just use the original source, and compile specifically in each app for each target. It would mean I have to make Webpack not ignore the node_modules folder. Also, Meteor by default doesn't touch the node_modules folder and I'm not sure how to make Meteor compile things (it uses Babel) from node_modules.

But yeah, I can't wait for Safari 10 either. It's going to have Proxy too, which will allow some interesting things!

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

Turns out I will not be using ES6 classes any more anyways (for now, because super is static, and constructors are not callable), and I am making a tool for multiple inheritance where in one implementation that involves method copying it simply breaks the super keyword at runtime unless using eval which loses the scope where the original method-to-be-copied was defined, and in the other implementation super works just fine but I need to have callable constructors which ES6 classes don't provide (and Proxy will make the implementation cleaner once Safari 10 is out).

The idea stemmed from my desire to do something like this:

import SomeClass from './SomeClass'
import OtherClass from './OtherClass'

class Foo extends multiple(SomeClass, OtherClass) {
  // ...
}

where SomeClass and OtherClass may have two completely separate prototype chains, or may simply be non-derived classes as in

export default
class SomeClass {
  // ..
}
export default
class OtherClass {
  // ..
}

from babel-preset-modern-browsers.

christophehurpeau avatar christophehurpeau commented on June 6, 2024

You can also consider building your library for several targets with several main, allowing you to choose with webpack which one you want in the end. Faster than rebuilding all node_modules with babel !

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

Him, I guess that would work but also multiply the size of the published package by the number of targets. Well, NPM and GitHub are free for open source projects, so I guess they are okay with that.

I can make a separate repo just for the releases on GitHub I suppose.

Sounds like a plan! 👍

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

@christophehurpeau When someone does

import SomeClass from 'my-library/path/to/SomeClass'

, how does that import for the proper target?

I know how to configure it in Webpack and Browserify, but Meteor and NPM both just look at imports relative to node_modules/my-library.

I feel like suggesting

import SomeClass from 'my-library/<target>/path/to/SomeClass'

where <target> is replaced with the actual target as in

import SomeClass from 'my-library/safari/path/to/SomeClass'

would be problematic because then the code relies on the <target> and is not portable across targets without having to find/replace all occurrences of <target>.

from babel-preset-modern-browsers.

christophehurpeau avatar christophehurpeau commented on June 6, 2024

I advise you to do single-file packages when possible. If not, you can either export everything in the main file, or create multiple entry-points and configure webpack to go look in the right directory.

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

A single-file package is not really always feasible, and may not help in tree-shaking. Sometimes classes don't make sense to be shipped in separate packages because they aren't intended to be standalone classes, and having them in different files of the same package helps keep code organized.

I guess really I should just write for my lowest common denominator target. I think modern-browsers and modern-browsers/safari may be that.

How do I read the compatibility table? Do I assume that modern-browsers compiles anything that says "No" in the table?

from babel-preset-modern-browsers.

christophehurpeau avatar christophehurpeau commented on June 6, 2024

Yes: "No" or the version is not the stable version

from babel-preset-modern-browsers.

trusktr avatar trusktr commented on June 6, 2024

Gotcha! Thanks! Would be nice if that was more apparent somehow.

from babel-preset-modern-browsers.

Related Issues (10)

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.