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:
ylemkimon
2021-10-31 04:23:56 +09:00
committed by GitHub
parent a28b2f084b
commit 15ee9b4a5a
3 changed files with 46 additions and 14 deletions

View File

@@ -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}');
```