Running workflow
Once you have cloned your new docs repository, you will want to be able to know how to start previews, lint, build, and do all the necessary things in development.
Ideally, you would be somewhat acquainted with npm
or yarn
project workflows, as Docusaurus is a React-based project.
๐จโ๐ป Committing to your repoโ
As part of running npm run prepare
when initializing this repo, husky
is installed to manage pre-commit hooks.
All commits are linted with commitlint
with the conventional rules found in package.json
.
lint-staged
is used to run checks on certain staged Git files when committing. The commands that are run and on what files can be found in the package.json
under the lint-staged
key.
It is recommended to use the command git commit
only after staging files.
You should generally avoid git commit -m
or similar commands which pass in the command-line or args like --allow-empty
.
See example of git commit flow
๐ฆ npm
commands and scriptsโ
Here is an exhaustive list of what each npm
script does in the package.json
.
This is likely to change every so often and documentation may not be updated to reflect it always.
Please open an issue or PR to address it!
๐ npm run start
โ
Run Docusaurus locally on port http://localhost:3000 to preview and supports automatic refresh when changes are made. This is usually used in development while making changes to Markdown or certain configuration files.
Not all changes made are supported by the automatic refresh and may require restarting the command.
๐ท npm run build
โ
Build Docusaurus for production into the ./build
directory of the root folder of this project.
It is usually not necessary to do this in development and is usually only used by CI when building to be deployed.
There is still an open issue regarding proper and stable CSS insertion ordering that may differ between npm run start
and npm run build
results.
Please see here for more details.
This is usually not an issue and can be mitigated with adding !important
to CSS styles.
๐ npm run build:docs
โ
If you have chosen to use docusaurus-plugin-openapi-docs
plugin for integrating OpenAPI to your docs, then this command will clean existing generated Markdown API docs and re-generate them.
This command is bundled into the npm run build
command.
You can safely remove this script from the package.json
if you are not using the plugin.
๐๏ธ npm run swizzle
โ
Swizzling allows more advanced customization of React Components in Docusaurus beyond simple CSS modifications.
โ๏ธ npm run deploy
โ
Built-in as part of Docusaurus for deploying project.
This command should not be necessary to use at all.
โฆ npm run clear
โ
If you are running into some issues with error when running npm run start
, it is recommended to use the clear command to remove all generated assets, caches or build artifacts.
๐บ npm run serve
โ
This is to be run after the npm run build
command as it will serve the files generated by the build output from the ./build
directory for local viewing.
As npm run build
is for production building or debugging production build issues, it should not be necessary to use npm runs serve
except where those two scenarios require it.
๐ npm run write-translations
โ
Only needed where translations are to be added.
๐ npm run write-heading-ids
โ
Only needed where translations are to be added.
โจ๏ธ npm run typecheck
โ
Typechecking with TypeScript and tsconfig.json
.
โจ๏ธ npm run typecheck-staged
โ
Typechecking staged-only files which is used by lint-staged
when committing.
๐งผ npm run lint
โ
Combined command which includes spell check, JS/TS linting, and CSS linting.
๐งผ npm run lint:js
โ
Lint JS/TS with ESLint.
๐งผ npm run lint:spelling
โ
Checking spelling with CSpell.
๐ Adding new words to the dictionaryโ
It's possible that you will use a word in your content that is not known to the linter, and your build, or commit, will fail.
If this happens, take a look at project-words.txt
in the root directory of your project; if the word that the linter caught is correctly spelled, and you wish it to pass the linter's test, add it to project-words.txt
, save, add and commit those changes, and see if it passes.
๐งผ npm run lint:style
โ
Lint CSS files with specific styling.
๐งผ npm run lint:fix
โ
Pass the --fix
CLI argument to npm run lint:js
to attempt to fix issues.
๐จ๏ธ npm run format
โ
Run Prettier to format code before commit for consistency in the repo.
๐ฅ npm run prepare
โ
After npm install
for the very first time, husky
is installed for Git pre-commit hooks.