Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate esm output for xterm.js #2486

Closed
torch2424 opened this issue Oct 18, 2019 · 7 comments
Closed

Generate esm output for xterm.js #2486

torch2424 opened this issue Oct 18, 2019 · 7 comments
Labels
type/proposal A proposal that needs some discussion before proceeding

Comments

@torch2424
Copy link

Hello!

Currently, we are using Rollup to handle our bundling. We recently upgraded from 3.14.5 to 4.10.0, and got the error of:

Screen Shot 2019-10-18 at 3 32 18 PM

I'll admit I didn't verify if it is correctly giving the name export since node_modules/xterm/lib/xterm.js is minified, or this honestly may be an issue with Rollup. But if I'm not mistaken, generating an esm build would also allow for better tree shaking, which according to bundlephobia currently is not supported.

Thanks! I'm open to opening this PR myself if needed, as I think it's a small change in the webpack config 😄

Looking forward to the response!

@Tyriar
Copy link
Member

Tyriar commented Oct 18, 2019

We build it as a UMD module:

libraryTarget: 'umd'

It looks like rollup supports it, we simplified the build a lot with v4 and combined the old direct TS output (lib) and the browserified output (dist) into a single umd module.

@torch2424
Copy link
Author

@Tyriar Thanks for the response! 😄

Oh yeah so I noticed it is currently output as a UMD. The fact that it doesn't work is probably a rollup issue. I'll dig a bit deeper once I get the chance 😄

That being said, I still think the esm would be worthwhile the extra build step for tree shaking. As, in theory, it could greatly reduce bundle size for a lot of apps. 🤔

Also, it would allow use to support the module field in package.json, instead of only main.

No worries if you don't see the value in it, was a suggestion for the project, and totally open to discussing it more. Let me know if there is something specifically I can do to provide more info, or help.

Thank you! 😄 👍

@Tyriar
Copy link
Member

Tyriar commented Oct 22, 2019

It doesn't look like module is supported/documented by npm? https://docs.npmjs.com/files/package.json

@mofux
Copy link
Contributor

mofux commented Oct 23, 2019

I've run some quick tests to see if we can support a module build relatively easy.

Unfortunately typescript itself does not support translating our absolute imports into relative ones (and there is not much hope that they will do soon: microsoft/TypeScript#33118 (comment)). There are hacks to get this working, but I'd rather not rely on them as they all seem very fragile.

The other option would be to use webpack to create the esm build for us, but unfortunately webpack does not support modules as a library target yet. There is hope that the not yet release webpack v5 can bring support for it: webpack/webpack#2933

I'd say let's revise this topic in a few month time and see if support in either webpack or typescript has been added.

@Tyriar Tyriar added type/proposal A proposal that needs some discussion before proceeding and removed needs more info labels Oct 23, 2019
@torch2424
Copy link
Author

@Tyriar

It doesn't look like module is supported/documented by npm? https://docs.npmjs.com/files/package.json

Ah yes, I don't think npm highlights it, since they focus on the "node" use case? But it is a common pattern. For instance, looking at comlink, their npm package has the module field and bundlers will respect it

@mofux

I've run some quick tests to see if we can support a module build relatively easy.

Ah, thank you very very much for looking into this! 😄

Unfortunately typescript itself does not support translating our absolute imports into relative ones (and there is not much hope that they will do soon: microsoft/TypeScript#33118 (comment)). There are hacks to get this working, but I'd rather not rely on them as they all seem very fragile.
The other option would be to use webpack to create the esm build for us, but unfortunately webpack does not support modules as a library target yet. There is hope that the not yet release webpack v5 can bring support for it: webpack/webpack#2933

Ah that's quite unfortunate, didn't know that Typescript and Webpack had troubles with this. Definitely not a smalled fix like I had originally though. Thanks for all the context and looking into this 👍

I'd say let's revise this topic in a few month time and see if support in either webpack or typescript has been added.

Totally, sounds like a good plan to me 😄

@Tyriar @mofux

You think it'd be a good idea to close this for now? Or keep it open for the future? I'm open to either 😄

@Tyriar
Copy link
Member

Tyriar commented Oct 23, 2019

Let's close for now since we're blocked on it, but feel free to open a new issue or comment on this one when webpack/webpack#2933 gets resolved. I think even if TS supported it as a target that wouldn't be enough since we use custom path mappings.

@Tyriar Tyriar closed this as completed Oct 23, 2019
@fatcerberus
Copy link

Regarding the import path rewriting, don’t hold out waiting for it to ever happen: microsoft/TypeScript#31643 (comment)

😦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/proposal A proposal that needs some discussion before proceeding
Projects
None yet
Development

No branches or pull requests

4 participants