Gathering detailed insights and metrics for gatsby-plugin-ts-config
Gathering detailed insights and metrics for gatsby-plugin-ts-config
Gathering detailed insights and metrics for gatsby-plugin-ts-config
Gathering detailed insights and metrics for gatsby-plugin-ts-config
npm install gatsby-plugin-ts-config
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
60 Stars
318 Commits
5 Forks
3 Watching
8 Branches
2 Contributors
Updated on 20 Nov 2022
TypeScript (99.38%)
JavaScript (0.62%)
Cumulative downloads
Total Downloads
Last day
-56.6%
745
Compared to previous day
Last week
-17%
5,882
Compared to previous week
Last month
1.6%
28,979
Compared to previous month
Last year
-25%
278,326
Compared to previous year
22
2
This plugin will allow you to write your
gatsby-*
configuration files in Typescript.
For v1 documentation, see the old docs
Install using your package manager
1npm install -D gatsby-plugin-ts-config
The cleanest way to use this plugin is to use gatsby-config.js
and gatsby-node.js
as pointers to your .ts
files that you keep in another directory. This isn't required,
though. All you need initially is gatsby-config.js
To point gatsby-config.js
and/or gatsby-node.js
to .ts
files:
1// gatsby-config.js 2const { useGatsbyConfig } = require("gatsby-plugin-ts-config"); 3 4// For static analysis purposes, you can use a callback with a require() statement 5module.exports = useGatsbyConfig(() => require("./config/gatsby-config"), opts); 6 7// A simpler method is to just use the filename 8module.exports = useGatsbyConfig("./config/gatsby-config", opts); 9 10// Or you can just return the `gatsby-config` object from the callback 11module.exports = useGatsbyConfig( 12 () => ({ 13 siteMetadata: { 14 ... 15 }, 16 plugins: [ 17 { 18 resolve: ..., 19 options: ..., 20 } 21 ] 22 }), 23 opts 24)
Once useGatsbyConfig
is called from gatsby-config
, gatsby-node.ts
can exist in your site's
root directory. However, if you do not wish to have your gatsby-config
in Typescript, useGatsbyConfig
is
not required. You can use this plugin directly from gatsby-node
if you wish.
1// gatsby-node.js 2const { useGatsbyNode } = require("gatsby-plugin-ts-config"); 3 4// All of the same usage patterns for `useGatsbyConfig` are valid for `useGatsbyNode` 5// as well 6module.exports = useGatsbyNode(() => require("./config/gatsby-node"), opts);
props
: Object
This "property bag" is an object that can take any shape you wish. When a gatsby-*
module is defined
with a function for a default export, these props
will be passed in the second parameter.
The property bag is mutable, so any changes you make to it will be passed to the next module
props
defined by your default
site will not be passed down to plugins.
props
is defined in both useGatsbyConfig
and useGatsbyNode
, the values in useGatsbyNode
will be
merged into the property bag before being passed on to default export of the module.type
: "babel" | "ts-node"
Determines which transpiler to use.
transpilerOptions
: Object
Any additional options you'd like to provide to the transpiler
type === "babel"
: See the babel options documentationtype === "ts-node"
: See the ts-node options documentationhooks
: Object
Allows you to hook into certain processes.
ignore
: Array<IgnoreHookFn>
IgnoreHookFn = (filename: string, origIgnore: boolean) => boolean
Override the rule set used to tell the transpiler to ignore files.
Receives two parameters:
Return a falsy or truthy value. It will be converted to boolean.
To use the value that would have been chosen by the internal process, return the second parameter.
The first true
or truthy value to be returned from your rule set will be used. The rest of the rule
set will be ignored
The default export is supported for your gatsby-*.ts
files. This is important to note, because Typescript
prefers that you use either the default export, or named exports.
While named exports are absolutely supported as well, some people may prefer to build their module object and then export it all at once. In that case, you may use the default export.
In other cases, you may want to perform some more advanced actions during the module processing. For this,
you may export a function as the default export. They will be called in order
(gatsby-config
-> gatsby-node
), and used to set the module's exports so that Gatsby can read them.
gatsby-config.ts
or gatsby-node.ts
may export a function as the default export. This will be called with
some details regarding the transpiling process, as well as some helpful information about the current project.
These modules may export this function as the default export whether or not they are in the root of your
site, as is the Gatsby standard. However, since this plugin needs to get kicked off by one of the
useGatsby*
plugins, gatsby-config
may not be accessible from the root.
These functions should return the object that Gatsby generally expects. For gatsby-config
, it would be
the same object you would define in gatsby-config.js
. For gatsby-node
, it would be the gatsby-node
APIs.
The default export function will receive two parameters:
The transpiler & project information
projectRoot
: The absolute path to the current project.imports
: All of the imports used by your gatsby-*
modules.
config
: string[]
node
: string[]
plugins
: Object
[pluginName: string]
: Object
config
: string[]
node
: string[]
The property bag defined in the bootstrap (useGatsby*
) functions.
If you feel a feature is missing, or you find a bug, please feel free to file an issue at https://github.com/Js-Brecht/gatsby-plugin-ts-config/issues.
I would also welcome any additions anybody would like to make.
If you enjoyed using this plugin, and you'd like to help support its development, you're welcome to donate!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
110 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