typescript#convertCompilerOptionsFromJson TypeScript Examples

The following examples show how to use typescript#convertCompilerOptionsFromJson. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From swc-node with MIT License 6 votes vote down vote up
export function loader(
  this: LoaderContext<{
    compilerOptions?: CompilerOptions
    configFile?: string
    fastRefresh?: boolean
  }>,
  source: string,
) {
  const callback = this.async()
  const { compilerOptions, configFile, fastRefresh } = this.getOptions() ?? {}
  const options = convertCompilerOptionsFromJson(compilerOptions, '').options ?? readDefaultTsConfig(configFile)
  const swcOptions = tsCompilerOptionsToSwcConfig(options, this.resourcePath)
  if (fastRefresh) {
    if (swcOptions.react) {
      swcOptions.react.refresh = true
    } else {
      swcOptions.react = {
        refresh: true,
      }
    }
  }
  transform(source, this.resourcePath, swcOptions)
    .then(({ code, map }) => callback(null, code, map))
    .catch((err) => callback(err))
}