How do you use es6 promises today on frontend?

前端 未结 3 727
庸人自扰
庸人自扰 2021-01-02 14:47

I\'m trying to use babel to compile file that contains es6 promises. I have installed babel-cli, babel-preset-es2015, babel-plugin-es6-promise.

My .babelrc config i

3条回答
  •  既然无缘
    2021-01-02 15:29

    Is there any possibility of using es6 promises today on frontend side without require js?

    In the latest Chrome/Firefox/Safari/Edge, Promises are already supported natively.

    If you're looking for an older browser support as well, an easy way without Babel is to just use a polyfill library.

    Here are libraries that have the exact behavior specified by the spec:

    • es6-promise
    • Native Promises Only

    And here are some with additional customized behavior:

    • BlueBird
    • Q

    Of course, the above are just some more popular ones but there are many others you can find by researching.

    If you do want to use other ES6 features, and especially on older browsers, you could keep adding polyfills but at that point it might be easier and more future-oriented to just use Babel and its env preset.


    Please provide any link to es6 promises implementation sample with babel (or even with babel + require because i can't get require js working as well)

    The babel website's setup describes how to use it in basically any environment you can think of. If webpack is too heavy for your needs, I'd recommend using gulp and here's a thorough guide on how

提交回复
热议问题