项目作者: developit

项目描述 :
Preact CLI plugin that adds converts async/await to Promises.
高级语言: JavaScript
项目地址: git://github.com/developit/preact-cli-plugin-async.git
创建时间: 2017-12-13T17:05:22Z
项目社区:https://github.com/developit/preact-cli-plugin-async

开源协议:

下载


preact-cli-plugin-async

npm travis greenkeeper

Preact CLI plugin that adds optimized support for async/await via fast-async.

Note: this is now just a copy of preact-cli-plugin-fast-async by @plusCubed.

Why do I want this?

ormally, transpiling async/await produces a large amount of code and depends on a runtime like regenerator-runtime. While that is optimal from a compatibility standpoint, it’s not so great for bundle size. Using fast-async, this plugin transforms your async functions into Promises just like you would write by hand!

It transforms this:

  1. async () => await (await fetch('/')).text()

… to something that roughly looks like this:

  1. function () {
  2. return Promise.resolve().then(function() {
  3. return fetch("/")
  4. }).then(function(e) {
  5. return e.text()
  6. })
  7. }

Pretty great, right?

Installation

  1. npm i -D preact-cli-plugin-async

… then include it in your project by creating a preact.config.js:

  1. import asyncPlugin from 'preact-cli-plugin-async';
  2. export default (config) => {
  3. asyncPlugin(config);
  4. }

License

MIT
Original version © developit
Current fast-async version © Daniel Ciao