Description
In MathJax v4.0.0-beta.7 AllPackages.ts
file was removed, and the document provide two ways to construt it manually
for the browser
<script type="importmap">
{
"imports": {
"#source/source.cjs": "https://cdn.jsdelivr.net/npm/[email protected]/components/mjs/source-lab.js"
}
}
</script>
<script type="module">
import {source} from 'https://cdn.jsdelivr.net/npm/[email protected]/components/mjs/source.js';
const load = Object.keys(source).filter((name) => name.substring(0,6) === '[tex]/').sort();
const packages = ['base'].concat(load.map((name) => name.substring(6)));
window.MathJax = {
loader: {load},
tex: {packages}
};
</script>
the document import the source.js
file from CDN
But I use the mathjax-full package in my frontend project, and use Vite as the bundler, and want to import the source.js
from the local package
and refer to the document for node app, use the following code to import source.js
import {source} from 'mathjax-full/components/src/source.js';
const AllPackages = Object.keys(source).filter((name) => name.substring(0,6) === '[tex]/').sort();
but the console throw the error like this
Caution
Uncaught ReferenceError: __dirname is not defined
I check out the /components/mjs/source.js
file, and find that it import the src
from the source.cjs
, which use the __dirname
and only available at node environment
if any other way to import the source.js
file for frontend project without using the CDN