Master issue for webpack/loadAddon issues
See original GitHub issueI’ve seen a bunch of issues recently come in around how loadAddon works and I wonder if we’re over complicating things. In today’s world of bundlers and source maps, it appears very difficult to get this right in a way that will work across all build systems.
Goals
- We need an easy way to load addons without forcing the user to download and parse/run the script. The core should be as slim as possible, leaving out optional components.
- It should work with webpack, browserify and vscode’s module system (and more?)
- It should work nicely with TypeScript
Current Situation
- We wrap addons in UMD which allows handling of the addon script in a plan browser environment, CommonJS environment and require.js environment. A problem here is that we needed to reorder the UMD definition as VS Code defines the
define
global, messing with the typical format and introducing issues for people eg. https://github.com/sourcelair/xterm.js/pull/994 - In a CommonJS environment the addon script attempts to load in the
Terminal
object viarequire
, this causes issues for webpack https://github.com/sourcelair/xterm.js/issues/927 Terminal
inside addons is not typed currently as the definition forTerminal
lies outside of the addon folder
Potential Solutions
I’m not attempting to solve the problem right now, here are some ideas though:
-
Have
loadAddon
pull in the script addon object and apply it toTerminal
, as opposed to leaving it up to the addon to loadTerminal
(see https://github.com/sourcelair/xterm.js/issues/927#issuecomment-325210992)public static loadAddon(addon: string, callback?: Function): boolean | any { // TODO: Improve return type and documentation if (typeof exports === 'object' && typeof module === 'object') { // CommonJS return require('./addons/' + addon + '/' + addon)(Terminal); } else if (typeof define === 'function') { ...
-
Require bundling or concatenation when using addons?
If anyone has more insights into how this sort of dynamic loading at runtime issue is typically handled, I’d love to hear it 😃
CCing people from related issues: @parisk @mofux @ficristo @dgriffen @ebertmi @rdicroce @jclangst @LucaT1 @jan0e @KagamiChan @vincentwoo
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:25 (19 by maintainers)
Top GitHub Comments
Why not just get rid of all the various module loader hacks and let the consumer deal with it? Maybe I’m missing something, but for me the easiest solution would be:
addon:
loadAddon:
consumer:
I am seeing source maps fail to parse as well, here is a full example error:
haven’t been able to get webpack to parse these files.