@faasjs/ts-transform

License: MITopen in new windowNPM Stable Versionopen in new windowNPM Beta Versionopen in new window

Typescript transform based on SWCopen in new window.

Install

npm install @faasjs/ts-transform

Usage

Use as a register

import { addHook } from 'pirates'
import { transform } from '@faasjs/ts-transform'

addHook((code, filename) => {
  if (filename.endsWith('.d.ts'))
    return ''

  return transform(code, { filename }).code
}, {
  exts: [
    '.jsx',
    '.ts',
    '.tsx'
  ]
})

Use as a rollup plugin

import { Plugin, rollup } from 'rollup'
import { bundle } from '@faasjs/ts-transform'

function tsTransform (): Plugin {
  return {
    name: 'tsTransform',
    async transform (code, filename) {
      return bundle({ filename })
    }
  }
}

export default {
  input: 'index.ts',
  output: {
    dir: 'dist',
    format: 'es',
  },
  plugins: [
    tsTransform(),
  ],
}

Modules

Variables

Functions

Variables

NodeBuiltinModules

Const NodeBuiltinModules: string[]

Functions

bundle

bundle(options): Promise<Output>

Parameters

NameTypeDescription
optionsObject-
options.externalModules?string[]has excluded node builtin modules
options.filenamestring-
options.jscTarget?JscTargetdefault: es2019
options.root?stringdefault: process.cwd()

Returns

Promise<Output>


transform

transform(code, options?): Output

Parameters

NameTypeDescription
codestring-
options?Object-
options.filename?string-
options.jsc?JscConfigswc compilation see https://swc.rs/docs/configuration/compilation
options.root?stringdefault: process.cwd()
options.target?JscTargetdefault: es2019

Returns

Output