mathjax / MathJax-src

MathJax source code for version 3 and beyond

Home Page:https://www.mathjax.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rollup not happy with __dirname

edemaine opened this issue · comments

I see from #420 that some Rollup compatibility is maybe desired. I was just trying to port my Web Worker application of MathJax from Webpack to Rollup. I noticed that Loader uses __dirname which is supported by Webpack but apparently not Rollup:

export function getRoot(): string {
let root = __dirname + '/../../es5';

In my case, I'm preloading all modules I want, so I don't really want to activate the Loader at all, except to initialize the preLoad list. Is there some way to bypass this? Maybe I should use direct mode?

I'm also not sure rollup is the best approach; it sadly doesn't seem to end up with smaller bundles. So probably not a high priority thing.

It looks like you have already converted to direct mode, so that should resolve the problem for you. You don't need the MathJax configuration object any longer, as that is only used by the startup and loader modules, which you aren't using. So the code

https://github.com/edemaine/tex2svg-webworker/blob/985dd617969dfc980baac1904425b9d0c9322eee/tex2svg.coffee#L49-L61

can be removed.

Alternatively, you could probably have used the original approach, by replacing

https://github.com/edemaine/tex2svg-webworker/blob/d80d9942b462a2cea9fde3d6fee64a427fc9e4d4/tex2svg.coffee#L11

with

require("mathjax-full/js/components/global.js");

https://github.com/edemaine/tex2svg-webworker/blob/d80d9942b462a2cea9fde3d6fee64a427fc9e4d4/tex2svg.coffee#L19

by

require("mathjax-full/js/components/startup.js");

and deleting

https://github.com/edemaine/tex2svg-webworker/blob/d80d9942b462a2cea9fde3d6fee64a427fc9e4d4/tex2svg.coffee#L21-L22

though I haven't tested it to make sure. In any case, it could have been worked out, but if you are not planning to use any of the loader functionality, there is not much reason to use the components approach. The direct calls are the better approach, here, I would say.

Many thanks, in particular for spotting that stray code! I confirmed that the direct port indeed works fine on Rollup. So, problem solved!