telenko / node-mf

57 stars 6 forks source link

Supporting ES5 module output (.mjs) #8

Open phoenix-ru opened 3 years ago

phoenix-ru commented 3 years ago

Is there a way to generate code which is compatible with ES5? Currently the code generated by the plugin uses require to link http(s), vm, etc. even when module output is explicitly enabled (output.module, experiments.outputModule, output.libraryTarget, output.chunkFormat, etc.). I believe that it is not a correct behaviour, as require is not available in the module context. On top of that, the plugin also uses exports, __dirname and similar globals, which is also problematic.

The reason that modules support is needed is that new Nuxt 3 uses modules output format and our company is interested in integrating Nuxt and Module Federation. I am willing to work on adding this feature to the plugin if my help is needed.

telenko commented 3 years ago

Hi @phoenix-ru , thanks for raising an issue. I agree that plugin injected code should depend on the module format. Will take a look.

phoenix-ru commented 3 years ago

Thank you for your answer, and by the way, I managed to solve it using unjs/mlly which shims the commonjs specifics in es modules. But it would be very nice to see it work out of the box without the need to inject this hack to the generated code 😃