@docusaurus/tsconfig - Support ts composite builds
closed
G
George
The default docusaurus template comes with a tsconfig configured to extend
@docusaurus/tsconfig
. However, the tsconfig.json file in the @docusaurus/tsconfig
package has the compiler option noEmit
set to true
. This prevents consumers from creating composite builds.Composite TS builds allow separating builds/checks of source code and other files (such as tests). In addition, this can help setting up development environments that provide accurate feedback through editors like VS Code.
An example of a composite build configured to support test files that use the source code types may look like the following
// tsconfig.docusaurus.json
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
// Allow other tsconfig files to reference this one
"composite": true,
"rootDir": "./",
"outDir": "./.tscheck-output/docusaurus"
},
// Tests require different globals, they are handled by another tsconfig
"exclude": [
"**/*.test.ts",
"**/*.test.tsx",
]
}
// tsconfig.test.json
{
"$schema": "http://json.schemastore.org/tsconfig",
"references": [
// Test files may import ts files that are included in the tsconfig.docusaurus.json program
{
"path": "./tsconfig.docusaurus.json"
}
],
"compilerOptions": {
"rootDir": "./",
"types": [
// Test environments have access to jest globals, hence the different tsconfig
"jest",
]
},
"include": [
"**/*.test.ts",
"**/*.test.tsx"
]
}
// tsconfig.json
// Root tsconfig.json file allows editors to automatically provide the proper feedback based on which of the referenced tsconfig files
// Targets the opened file
{
"references": [
{
"path": "./tsconfig.docusaurus.json"
},
{
"path": "./tsconfig.test.json"
}
]
}
## Conclusion
It is reasonable that the tsconfig provided by
@docusaurus/tsconfig
has noEmit
set to true, but it would be great if it did not include this flag and allowed the consumer to choose how they'd like to compose their ts builds, or at least provide a separate config that is less opinionated.Joshua Chen
closed
Joshua Chen
We don't use tsc to build anything. As explained in the docs, all TypeScript is bundled with Webpack; tsc is just for type checking and editor type hints.
If you have a sufficiently complex project where you even need to write tests for your components and build them using a separate pipeline, I would suggest you (a) use a separate tsconfig (b) split these components out into a separate package.