【问题标题】:How to use Gatsby with TypeScript and Netlify functions如何将 Gatsby 与 TypeScript 和 Netlify 函数一起使用
【发布时间】:2021-04-28 22:44:51
【问题描述】:

我使用 this tutorial 设置了带有 Netlify 功能的 Gatsby, 一切都按预期工作,除了我喜欢将 TypeScript 用于无服务器函数代码。

Gatsby 构建命令将前端 typescript 转换为 javascript,所以我想我需要一个自定义构建脚本来转换 typescript 无服务器功能代码,并以“节点”为目标。 我怎样才能做到这一点?任何帮助表示赞赏。

【问题讨论】:

    标签: typescript babeljs gatsby serverless netlify


    【解决方案1】:

    我认为您正在寻找这个无服务器插件 (serverless-plugin-typescript)。安装后:

    yarn add --dev serverless-plugin-typescript typescript
    # or
    npm install -D serverless-plugin-typescript typescript
    

    你需要配置你的serverless.yml:

    plugins:
      - serverless-plugin-typescript
    

    您只需在tsconfig.json 中添加您的TypeScript 自定义配置,例如:

    {
      "compilerOptions": {
        "preserveConstEnums": true,
        "strictNullChecks": true,
        "sourceMap": true,
        "allowJs": true,
        "target": "es5",
        "outDir": ".build",
        "moduleResolution": "node",
        "lib": ["es2015"],
        "rootDir": "./"
      }
    }
    

    【讨论】:

      【解决方案2】:

      我问的问题不复存在:Netlify Functions now support TypeScript

      【讨论】:

        猜你喜欢
        • 2019-07-14
        • 2022-01-05
        • 2020-10-13
        • 2016-06-22
        • 2019-07-30
        • 1970-01-01
        • 1970-01-01
        • 2020-06-28
        • 2019-10-11
        相关资源
        最近更新 更多