-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TypeScript in Docusaurus config #7911
Comments
Definitely on our roadmap. You can use |
GREAT JOB! |
We'll keep it open. It's on our todo list. |
I just tried the script based on But it would fail when using alias, e.g. Since the ts-node has been used, it's natural now to combiine it with I modified like this: 'use strict';
// source: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/website/docusaurus.config.js
// ref of tsconfig-paths: https://github.com/dividab/tsconfig-paths#bootstrapping-with-explicit-params
+ require("tsconfig-paths").register({
+ baseUrl: "./",
+ paths: require("./tsconfig.json").compilerOptions.paths,
+ });
require('ts-node').register({
scope: true,
scopeDir: __dirname,
swc: true,
transpileOnly: true,
});
module.exports = require('./config/src/index.ts'); And a manual alias is in need since {
"compilerOptions": {
"resolveJsonModule": true, // can be omitted, maybe has been handled by ts-node
"esModuleInterop": true, // cannot be omitted
"paths": { // handle the path aliases
"@site/*": ["./*"]
}
}
} Thanks for all of your great work, you did save me a lot of time and enlighten me as well ~ |
For reference Gatsby recently added support for TS config files. That's worth studying their solution for the final implementation: gatsbyjs/gatsby#34613 I also found this interesting: https://github.com/egoist/bundle-require |
Have you read the Contributing Guidelines on issues?
Description
Here I would offer a minimal example on how to create a config file based on typescript and make it run.
Has this been requested on Canny?
No response
Motivation
In TypeScript Support | Docusaurus, it writes that
It is not possible to use a TypeScript config file in Docusaurus unless you compile it yourself to JavaScript.
Although JSDoc can be helpful of preventing you make some mistakes about field types, it's not acting well in every places.
Take my own example, I designed an data structure for frontend, and I also need to generate the data from the backend (i.e.
customFileds
indocusaurus.config.js
), then I would suffer with types declaration:And a typescript config is necessary to me.
API design
Source Code
Attention
path alias
in our ts config file, since it would introduce troubles when transpiling into js,tsconfig-paths
ortsc-alias
may be helpful if you need it.outDir
androotDir
intsconfig.json
, but it would fail if usingtsc-alias
at the same time since aoutDir
is need.docusaurus.config.js
did, but the config would become harder to manage as you have seen.Other Practices
I also tried to use webpack to pack all the ts files into one
docusaurus.config.webpack.js
file and almost succeded with these settings:But it failed with the unknown error
request argument is not a string
, which seems raised by the webpack inner docusaurus.Have you tried building it?
No response
Self-service
The text was updated successfully, but these errors were encountered: