Docs
CLI
NAPI Config

NAPI Config

The config schema of NAPI-RS.

💡
All the fields in napi is optional.

Schema

{
  napi?: {
    binaryName?: string
    targets?: string[],
    packageName?: string,
    npmClient?: string
    constEnum?: boolean
    dtsHeader?: string
    dtsHeaderFile?: string
    wasm?: {
      initialMemory?: number
      maximumMemory?: number
      browser?: {
        fs?: boolean
        asyncInit?: boolean
      }
    }
  }
}
FieldDefaultDescription
binaryNameindexThe binary file name of generated .node file. Eg [NAME].[TRIPLE?].node becomes index.win32-x64-msvc.node
targets[]Targets you want to build. Target triples could be found in the output of rustup target list command.
packageNameundefinedOverride the name field in package.json. See Build#js-package-name for usage.
npmClientnpmSpecify a different NPM client for usage when executing NPM actions such as publishing.
constEnumfalseWhether to generate const enum for the generated index.d.ts file.
dtsHeaderundefinedHeader string that prepend to the generated index.d.ts file.
dtsHeaderFileundefinedFile path that contains the header string that prepend to the generated index.d.ts file. If both dtsHeader and dtsHeaderFile are provided, dtsHeaderFile will be used
wasm.initialMemory4000 (256mb)Initial memory size for the generated WebAssembly module. See WebAssembly.Memory (opens in a new tab) for more details.
wasm.maximumMemory65536 (4GiB)Maximum memory size for the generated WebAssembly module. See WebAssembly.Memory (opens in a new tab) for more details.
wasm.browser.fsfalseWhether to enable the node:fs module polyfill for the generated WebAssembly module.
wasm.browser.asyncInitfalseWhether to enable the async initialization for the generated WebAssembly module.

What is target triple

See rustc/platform-support (opens in a new tab) and LLVM/CrossCompilation (opens in a new tab)

Targets are identified by their "target triple" which is the string to inform the compiler what kind of output that should be produced.

The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where:

  • arch = x86_64, i386, arm, thumb, mips, etc.
  • sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.
  • vendor = pc, apple, nvidia, ibm, etc.
  • sys = none, linux, win32, darwin, cuda, etc.
  • abi = eabi, gnu, android, macho, elf, etc.