How should a RequireJS transpilation plugin return its result?

女生的网名这么多〃 提交于 2020-05-17 07:28:05

问题


Transpilation plugins like es6!, es!, and cs! are more complicated than simple plugins like text! because they return javascript modules that have their own dependencies.

Specifically, the code I've seen loads the specified file through XHR, transforms it, and then returns the result via a call like

onload.fromText("define(['foo', 'bar', ...");

That works fine for small test cases but throws a "Mismatched anonymous define() module" exception when running in my actual app. It's a race condition that happens when RequireJS is simultaneously processing a bunch of normal JS requires at the same time as evaluating a bunch of plugin requires.

Is this just a RequireJS bug, or is the plugin doing it wrong? Or, is it just not supported? Despite multiple transpilation plugin examples on the web, the RequireJS doc on that error says that

If you use the loader plugins or anonymous modules (modules that call define() with no string ID) but do not use the RequireJS optimizer to combine files together, this error can occur.

来源:https://stackoverflow.com/questions/60199058/how-should-a-requirejs-transpilation-plugin-return-its-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!