Add documentation regarding importing the module (#1768)

This commit is contained in:
ylemkimon
2018-11-06 00:37:44 +09:00
committed by GitHub
parent f713f324bd
commit cda184bea4
4 changed files with 106 additions and 24 deletions

View File

@@ -2,7 +2,8 @@
id: node
title: Node.js
---
## npm
## Installation
### npm
Install with `npm`:
```bash
@@ -11,7 +12,7 @@ npm install katex
npm install -g katex
```
## Yarn
### Yarn
Install with `Yarn`:
```bash
@@ -20,8 +21,7 @@ yarn add katex
yarn global add katex
```
## Building from Source
### Building from Source
To build you will need Git, Node.js 6.9 or later, and Yarn.
Clone a copy of the GitHub source repository:
@@ -36,5 +36,33 @@ yarn
yarn build
```
If you'd like to use the built KaTeX in other projects, install the package by
specifying the path:
```bash
yarn add /path/to/KaTeX
# or using npm
npm install /path/to/KaTeX
```
> You can manually download the package and source code from
[GitHub releases](https://github.com/Khan/KaTeX/releases).
## Importing
KaTeX is exported as a CommonJS module, which can be imported using `require`:
```js
const katex = require('katex');
```
If you're using a module loader, transpiler, or bundler that supports interoperability
between ECMAScript module and CommonJS module, you can use `import`:
```js
import katex from 'katex';
```
KaTeX also provides an ECMAScript module:
```js
import katex from 'katex/dist/katex.mjs'
```
> The ES module contains ES6 syntaxes and features, and may need transpiling to
use in old environments: