//unplugin-quansyncbyBobbieGoede

unplugin-quansync

Write async functions, get both async and sync functions

0
0
0

unplugin-quansync npm

Unit Test

Write async functions, get both async and sync functions with
quansync and compiler magics.

Installation

npm i -D unplugin-quansync
Vite
// vite.config.ts
import Quansync from 'unplugin-quansync/vite'

export default defineConfig({
  plugins: [Quansync()],
})


Rollup
// rollup.config.js
import Quansync from 'unplugin-quansync/rollup'

export default {
  plugins: [Quansync()],
}


Rolldown
// rolldown.config.js
import Quansync from 'unplugin-quansync/rolldown'

export default {
  plugins: [Quansync()],
}


esbuild
import { build } from 'esbuild'
import Quansync from 'unplugin-quansync/esbuild'

build({
  plugins: [Quansync()],
})


Webpack
// webpack.config.js
import Quansync from 'unplugin-quansync/webpack'

export default {
  /* ... */
  plugins: [Quansync()],
}


Rspack
// rspack.config.js
import Quansync from 'unplugin-quansync/rspack'

export default {
  /* ... */
  plugins: [Quansync()],
}


Usage

import fs from 'node:fs'
import { quansyncMacro } from 'quansync'

// Create an quansync function by providing `sync` and `async` implementations
const readFile = quansyncMacro({
  sync: (path: string) => fs.readFileSync(path),
  async: (path: string) => fs.promises.readFile(path),
})

// Create an quansync function by providing a **async** function
const myFunction = quansyncMacro(async function (filename) {
  // Use `await` to call another quansync function
  const code = await readFile(filename, 'utf8')

  return `// some custom prefix\n${code}`
})

// Use it as a sync function
const result = myFunction.sync('./some-file.js')

// Use it as an async function
const asyncResult = await myFunction.async('./some-file.js')

For more details, please refer to the
quansync documentation.

Sponsors

License

MIT License © 2025-PRESENT 三咲智子

[beta]v0.13.0