mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 03:08:40 +00:00
feat: conditionally export ECMAScript modules (#3377)
* feat: conditionally export ECMAScript modules BREAKING CHANGE: With module loaders that support conditional exports and ECMAScript modules, `import katex from 'katex';` will import the ECMAScript module. You can now use: |Before |After | |------------------------------------------|----------------------------------| |`require('katex/dist/contrib/[name].js')` | `require('katex/contrib/[name]')`| |`import katex from 'katex/dist/katex.mjs'`| `import katex from 'katex'` | |`import 'katex/dist/contrib/[name].mjs'` | `import 'katex/contrib/[name]'` |
This commit is contained in:
10
docs/node.md
10
docs/node.md
@@ -63,17 +63,11 @@ KaTeX is exported as a CommonJS module, which can be imported using `require`:
|
||||
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`:
|
||||
KaTeX also conditionally exports an ECMAScript module:
|
||||
```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.
|
||||
|
||||
@@ -94,6 +88,6 @@ mhchem in Node as follows:
|
||||
|
||||
```js
|
||||
const katex = require('katex');
|
||||
require('katex/dist/contrib/mhchem.js'); // modify katex module
|
||||
require('katex/contrib/mhchem'); // modify katex module
|
||||
const html = katex.renderToString('\\ce{CO2 + C -> 2 C0}');
|
||||
```
|
||||
|
Reference in New Issue
Block a user