问题
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