mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
feat: create official TypeScript base config @docusaurus/tsconfig (#9050)
This commit is contained in:
parent
6102a5a671
commit
012b285805
13 changed files with 63 additions and 18 deletions
|
@ -35,5 +35,18 @@ cd `git rev-parse --show-toplevel` # Back to repo root
|
||||||
rm -rf test-website-in-workspace
|
rm -rf test-website-in-workspace
|
||||||
yarn create-docusaurus test-website-in-workspace classic
|
yarn create-docusaurus test-website-in-workspace classic
|
||||||
cd test-website-in-workspace
|
cd test-website-in-workspace
|
||||||
|
yarn build
|
||||||
|
yarn start
|
||||||
|
```
|
||||||
|
|
||||||
|
For the TypeScript template:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd `git rev-parse --show-toplevel` # Back to repo root
|
||||||
|
rm -rf test-website-in-workspace
|
||||||
|
yarn create-docusaurus test-website-in-workspace classic --typescript
|
||||||
|
cd test-website-in-workspace
|
||||||
|
yarn typecheck
|
||||||
|
yarn build
|
||||||
yarn start
|
yarn start
|
||||||
```
|
```
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0",
|
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0",
|
||||||
"@tsconfig/docusaurus": "^1.0.5",
|
"@docusaurus/tsconfig": "^3.0.0-alpha.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
// This file is not used in compilation. It is here just for a nice editor experience.
|
// This file is not used in compilation. It is here just for a nice editor experience.
|
||||||
"extends": "@tsconfig/docusaurus/tsconfig.json",
|
"extends": "@docusaurus/tsconfig",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "."
|
"baseUrl": "."
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import React from 'react';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
|
|
20
packages/docusaurus-tsconfig/package.json
Normal file
20
packages/docusaurus-tsconfig/package.json
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "@docusaurus/tsconfig",
|
||||||
|
"version": "3.0.0-alpha.0",
|
||||||
|
"description": "Docusaurus base TypeScript configuration.",
|
||||||
|
"main": "tsconfig.json",
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"tsconfig",
|
||||||
|
"typescript",
|
||||||
|
"docusaurus"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/facebook/docusaurus.git",
|
||||||
|
"directory": "packages/docusaurus-tsconfig"
|
||||||
|
},
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
23
packages/docusaurus-tsconfig/tsconfig.json
Normal file
23
packages/docusaurus-tsconfig/tsconfig.json
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
|
"display": "Docusaurus",
|
||||||
|
"docs": "https://docusaurus.io/docs/typescript-support",
|
||||||
|
"compilerOptions": {
|
||||||
|
"allowJs": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"lib": ["DOM"],
|
||||||
|
"moduleResolution": "Node16",
|
||||||
|
"noEmit": true,
|
||||||
|
"types": [
|
||||||
|
"node",
|
||||||
|
"@docusaurus/module-type-aliases",
|
||||||
|
"@docusaurus/theme-classic"
|
||||||
|
],
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@site/*": ["./*"]
|
||||||
|
},
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,14 +21,14 @@ Below are some guides on how to migrate an existing project to TypeScript.
|
||||||
To start using TypeScript, add `@docusaurus/module-type-aliases` and the base TS config to your project:
|
To start using TypeScript, add `@docusaurus/module-type-aliases` and the base TS config to your project:
|
||||||
|
|
||||||
```bash npm2yarn
|
```bash npm2yarn
|
||||||
npm install --save-dev typescript @docusaurus/module-type-aliases @tsconfig/docusaurus
|
npm install --save-dev typescript @docusaurus/module-type-aliases @docusaurus/tsconfig
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add `tsconfig.json` to your project root with the following content:
|
Then add `tsconfig.json` to your project root with the following content:
|
||||||
|
|
||||||
```json title="tsconfig.json"
|
```json title="tsconfig.json"
|
||||||
{
|
{
|
||||||
"extends": "@tsconfig/docusaurus/tsconfig.json",
|
"extends": "@docusaurus/tsconfig",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "."
|
"baseUrl": "."
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@docusaurus/eslint-plugin": "^3.0.0-alpha.0",
|
"@docusaurus/eslint-plugin": "^3.0.0-alpha.0",
|
||||||
"@tsconfig/docusaurus": "^1.0.7",
|
"@docusaurus/tsconfig": "^3.0.0-alpha.0",
|
||||||
"@types/jest": "^29.4.0",
|
"@types/jest": "^29.4.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"rimraf": "^3.0.2"
|
"rimraf": "^3.0.2"
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
{
|
{
|
||||||
// This file is not used in compilation. It is here just for a nice editor experience.
|
// This file is not used in compilation. It is here just for a nice editor experience.
|
||||||
"extends": "@tsconfig/docusaurus/tsconfig.json",
|
"extends": "@docusaurus/tsconfig",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "preserve", // TODO add to preset config
|
|
||||||
|
|
||||||
"lib": ["DOM", "ESNext"],
|
"lib": ["DOM", "ESNext"],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
|
||||||
// Duplicated from the root config, because TS does not support extending
|
// Duplicated from the root config, because TS does not support extending
|
||||||
// multiple configs and we want to dogfood the @tsconfig/docusaurus one
|
// multiple configs and we want to dogfood the @docusaurus/tsconfig one
|
||||||
"allowUnreachableCode": false,
|
"allowUnreachableCode": false,
|
||||||
"exactOptionalPropertyTypes": false,
|
"exactOptionalPropertyTypes": false,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
|
|
@ -2818,11 +2818,6 @@
|
||||||
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"
|
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"
|
||||||
integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==
|
integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==
|
||||||
|
|
||||||
"@tsconfig/docusaurus@^1.0.5", "@tsconfig/docusaurus@^1.0.7":
|
|
||||||
version "1.0.7"
|
|
||||||
resolved "https://registry.yarnpkg.com/@tsconfig/docusaurus/-/docusaurus-1.0.7.tgz#a3ee3c8109b3fec091e3d61a61834e563aeee3c3"
|
|
||||||
integrity sha512-ffTXxGIP/IRMCjuzHd6M4/HdIrw1bMfC7Bv8hMkTadnePkpe0lG0oDSdbRpSDZb2rQMAgpbWiR10BvxvNYwYrg==
|
|
||||||
|
|
||||||
"@types/acorn@^4.0.0":
|
"@types/acorn@^4.0.0":
|
||||||
version "4.0.6"
|
version "4.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/@types/acorn/-/acorn-4.0.6.tgz#d61ca5480300ac41a7d973dd5b84d0a591154a22"
|
resolved "https://registry.yarnpkg.com/@types/acorn/-/acorn-4.0.6.tgz#d61ca5480300ac41a7d973dd5b84d0a591154a22"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue