JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 130
  • Score
    100M100P100Q80082F
  • License MIT

Write async functions, get both async and sync functions

Package Exports

  • unplugin-quansync
  • unplugin-quansync/api
  • unplugin-quansync/esbuild
  • unplugin-quansync/farm
  • unplugin-quansync/rolldown
  • unplugin-quansync/rollup
  • unplugin-quansync/rspack
  • unplugin-quansync/vite
  • unplugin-quansync/webpack

Readme

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 三咲智子