Gathering detailed insights and metrics for gatsby-plugin-ts
Gathering detailed insights and metrics for gatsby-plugin-ts
Gathering detailed insights and metrics for gatsby-plugin-ts
Gathering detailed insights and metrics for gatsby-plugin-ts
gatsby-plugin-ts-config
Configure Gatsby to use Typescript configuration files
@vercel/gatsby-plugin-vercel-builder
This plugin generates [Vercel Build Output API v3](https://vercel.com/docs/build-output-api/v3) for Gatsby v4+ projects.
@vercel/gatsby-plugin-vercel-analytics
Track Core Web Vitals in Gatsby projects with Vercel Speed Insights.
babel-preset-gatsby
Gatsby uses the phenomenal project [Babel](https://babeljs.io/) to enable support for writing modern JavaScript — while still supporting older browsers. This package contains the default Babel setup for all Gatsby projects.
npm install gatsby-plugin-ts
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
122 Stars
152 Commits
18 Forks
4 Watching
25 Branches
14 Contributors
Updated on 03 Apr 2024
TypeScript (78.57%)
JavaScript (14.86%)
CSS (6.56%)
Cumulative downloads
Total Downloads
Last day
30.9%
364
Compared to previous day
Last week
12.4%
1,861
Compared to previous week
Last month
-3.2%
7,630
Compared to previous month
Last year
0.7%
110,542
Compared to previous year
3
4
An alternative to the official typescript plugin, with ts-loader
& automatic type generation for your graphql queries (using graphql-code-generator
)
Hi there 👋 Are you just looking for a way to generate graphql types for your graphql queries?
gatsby-plugin-graphql-codegen
is what you want. However, other maintainers and I haven't been able to keep this repo up to shape. Please have a look at @cometkim's graphql-plugin-typegen which does almost the same thing & better maintained. Still, ideas & PRs are all welcomed. If you'd like to help maintain this project, please feel free to reach out. Thank you, have a great day!
This monorepo houses 2 packages:
npm package | Description | Docs |
---|---|---|
gatsby-plugin-ts | alternative typescript support with ts-loader & automated graphql codegen via graphql-code-generator | docs |
gatsby-plugin-graphql-codegen | automated graphql codegen via graphql-code-generator | docs |
Quick links: Acknowledgement • General Q&A • Contribute
Special thanks to the contributors, who have improved this project with code, bug reports & suggestions:
Do you want to send a PR? see this section
This project is built upon these awesome projects:
TypeStrong projects:
The Guild's projects:
And of course, Gatsbyjs and Typescript
Here's a list of common questions I've seen since releasing this project. If you have a question that's not here, please don't hesitate to open an issue!
gatsby-plugin-ts
?
Gatsby use babel-preset-typescript
which strips type information out of your code without doing typecheck. gatsby-plugin-ts
use ts-loader
, so you don't have to (1) worry about the caveats of babel-preset-typescript
or (2) use an IDE / code editor that can typecheck for you.
It also generate typings for your graphql queries, make it easier to strengthen your code.
If you're already using something like VSCode and/or don't want to do typecheck in production, you can toggle off the typecheck option.
gatsby-plugin-ts
and gatsby-plugin-graphql-codegen
?
Originally belong to the same plugin, the codegen portion was extracted to gatsby-plugin-graphql-codegen
so it can be used with the official typescript plugin. If you are already using gatsby-plugin-ts
, you don't need gatsby-plugin-graphql-codegen
.
It's up to your preference.
Maybe<T>
?
It's due to Gatsby internal. There's an effort to make typing more strict here.
You also may find the new optional chaining & nullish coalescing operator in typescript 3.7 helpful to deal with this.
Yes! You can also use node env to determine whether to enable these features.
1// gatsby-config.js 2{ 3 resolve: `gatsby-plugin-ts`, 4 options: { 5 codegen: false, 6 typeCheck: process.env.NODE_ENV === 'development', 7 } 8},
null
Gatsby extract graphql queries statically and it only understand queries inside template literal. It's possible that tsc is transpiling your template literal to string concat quivalent. Check your tsconfig.json
& make sure you have a setting similar to this:
1"compilerOptions": { 2 "target": "ES2018", /* or at least ES2015 */ 3 "module": "ESNext", /* or at least ES2015 */ 4 "lib": ["dom"], /* <-- required! */ 5 "jsx": "preserve", /* <-- required! */ 6 "moduleResolution": "node", /* <-- required! */ 7 /* other options... */ 8}
You'd have to update your tsconfig
with the below options:
1 "allowJs": true, 2 "outDir": "./build"
The outDir
option won't be used by ts-loader, but you may need it to satisfy vscode.
If you are using gatsby-plugin-ts
, before you go off and install a bunch of babel plugins like a lot of tutorials suggest, check if your compilation target
in tsconfig.json
is too high (ESNext
or ES2019
).
With these targets, tsc will leave the new syntax as-is, which babel might not understand. Downgrade them to ES2018
should fix the issue; also make sure your IDE's typescript version is the same as the one listed in your package.json
dependency.
Yes, but it's not easy at the moment. We're working on it; stay tuned!
We're trying to pin down why this happens, please share your experience in #36
Gatsby recently moved plugins' fragments from .cache
to node_modules
. We currently support both paths, but sometimes it may cause conflict warnings & errors:
If you are annoyed by this warning, set the documentPaths
options as below:
1// gatsby-config.js 2{ 3 resolve: 'gatsby-plugin-graphql-codegen', 4 options: { 5 documentPaths: [ 6 './src/**/*.{ts,tsx}', 7 './node_modules/gatsby-*/**/*.js', 8 ], 9 } 10},
We will remove the .cache/fragments
path and bump gatsby peer dependency version in a later release.
Update: Since 2.4.0, we've removed .cache/fragments
& bump up gatsby peer dep.
Duplicate identifier 'GatsbyImageSharpFixedFragment'
If you see this error please run a gatsby clean
to remove fragments in .cache
, or set the documentPaths
options as below:
1// gatsby-config.js 2{ 3 resolve: 'gatsby-plugin-graphql-codegen', 4 options: { 5 documentPaths: [ 6 './src/**/*.{ts,tsx}', 7 './node_modules/gatsby-*/**/*.js', 8 ], 9 } 10},
Unknown identifier 'GatsbyImageSharpFixedFragment'
in a yarn/lerna monorepo
Are you using a monorepo? It's possible that the missing fragment's plugin is 'hoisted' (moved to workspace root's node_modules
). A simple fix is use a nohoist
config, supported by both lerna & yarn. Here's an example with yarn workspace, where gatsby-transformer-sharp
is always installed in its project's node_modules
.
in your root's package.json
1"workspaces": { 2 "packages": ["packages/*"], 3 "nohoist": [ 4 "**/gatsby-transformer-sharp" 5 ] 6}
All PRs / issues are welcomed.
Steps to run in development:
1# 0 2git clone https://github.com/d4rekanguok/gatsby-typescript.git && cd gatsby-typescript 3 4# 1 Install deps 5yarn 6 7# 2 Hook up dependencies 8yarn bootstrap 9 10# 3 Build binaries 11lerna run build 12 13# 4 Run test 14yarn test
You can test your code against the starters inside the repo. Don't forget to checkout the changes in those repo before sending a PR. Alternatively, use yalc to test the plugins in your own Gatsby project:
1# 1 Install yalc 2npm i yalc -G 3 4# 2 cd into, say, gatsby-plugin-ts 5cd packages/gatsby-plugin-ts 6 7# 3 Publish to yalc 8yalc publish 9 10# 4 cd into your gatsby project 11cd ../../my-gatsby-project 12 13# 5 Install yalc & re-install deps 14npm uninstall gatsby-plugin-ts && yalc add gatsby-plugin-ts 15 16npm install 17 18# 6 Subsequent update 19yalc update 20 21# 7 Done? remove yalc deps 22yalc remove --all
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 8/26 approved changesets -- score normalized to 3
Reason
project is archived
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
92 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More