MatAtBread / fast-async

605 stars 21 forks source link

Add note aboud position on directive #57

Closed Strate closed 5 years ago

gitgrimbo commented 5 years ago

+1 for this doc update.

This is how I am using fast-async in my main.jsx file (which itself doesn't have any 'real' use of async/await inside it, so I put some dummy code in there)...

// TOP OF main.jsx
// https://github.com/MatAtBread/fast-async#runtimepattern
// Note: At least one of the file(s) matching the "runtimePattern" must use either await or async
// as the runtime function (or require('nodent-runtime') if you set "useRuntimeModule":true) is
// only included for files that reference it.
"use runtime-nodent";
// fake async function to trigger inclusion of fast-async runtime.
(async () => { });

which for my build gets transpiled into Promise-based code, but because this anonymous function is not used, it can get removed by a code minifier.

And a snip from my webpack config:

plugins: [
  // web needs to use Promises for async/await support (basically to support IE11)
  // use fast-async because it is Promise based and not generator based
  // (IE doesn't support generators)
  ["fast-async", {
    "runtimePattern": "main\\.jsx",
  }],